"Android" Uses-permission and permission detailed

Source: Internet
Author: User


1.<uses-permission>:

Official Description:

If An application needs access to a feature protected by a permission, it must declare the IT requires that Permissio N with a<uses-permission>element in the manifest. Then, when the application was installed on the device, the installer determines whether or not to grant the requested Perm Ission by checking the authorities so signed the application ' s certificates and, in some cases, asking the user. If the permission is granted, the application are able to use the protected features. If not, it attempts to access those features would simply fail without any notification to the user.


if an application needs to access a permission protected feature, the app must declare its required permissions in manifest with the <uses-permission> node. When the app is installed on the device, the installer will decide whether or not to grant the permission it claims, which sometimes asks the user. If the permission is granted, the app can use the protected attribute, otherwise the access fails and the user is not notified.


Note: It is not necessary to call other applications to declare <uses-permission>, and sometimes even to invoke the components of the program you are applying to declare!!! (The following example will be said)


2.<permission>:

an application can also protect its own components (activities, services, broadcast RECEIV ERS, and content providers) with permissions. It can employ any of the permissions defined by Android (listed Inandroid. Manifest.permission ) or declared by other applications. Or It can define its own. A new permission is declared with The <PERMISSION> &NBSP;ELEMENT.&NBSP;


An application can also be used permissions protects its own components by using an Android-defined or other application-defined permissions, If you want to define a new permission, you can use < Permission>   nodes to define. As follows:

<permission android:Description="string Resource"            android:icon="drawable Resource"            android:label="string Resource"            android:name="string"            android:Permissiongroup="string"            android:ProtectionLevel=["Normal" | "Dangerous" | "Signature" | "Signatureorsystem"] />

For example, a activity could be protected as follows:

<manifest >    <permission android:name= "Com.example.project.DEBIT_ACCT" .../>    < Uses-permission android:name= "Com.example.project.DEBIT_ACCT"/>    ...    <application. .>        <activity android:name= "com.example.project.FreneticActivity"                  android: permission= "Com.example.project.DEBIT_ACCT" ...                  > ...        </activity>    </application></manifest>

note that, in this example, The debit_acct  permission is not a declared with The <PERMISSION>  element, its use was also requested with The <USES-PERMISSION>  element. Its use must is requested in order for other components of the application to launch the protected activity, even though T He protection is imposed by the application itself.

if, in the same example, The permission  attribute is set to a permission declared elsewhere (such asandroid.permission.call_emergency_numbers , it would not has been necessary to declare it again With A<PERMISSION>  element . However, it would still has been necessary to request its use With <USES-PERMISSION> .


Note that in this example, DEBIT_ACCT this permission is not only declared in <permission>, but also declared in <uses-permission>, in order to start the protected activity in other components of the application , it is necessary to declare DEBIT_ACCT in <uses-permission>, even if this protection is added by the application itself. (This confirms the 1th said above).

Note that if the added permission is defined elsewhere, there is no need to declare the <permission> again, but still use <uses-permission> to declare this permission.

Reference:

Http://developer.android.com/guide/topics/manifest/manifest-intro.html#perms

http://berdy.iteye.com/blog/1782854

http://blog.csdn.net/lilu_leo/article/details/6940941




"Android" Uses-permission and permission detailed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.