Android Custom Permissions (<permission> <uses-permission>)

Source: Internet
Author: User

In the security model of the Android system, the application is not allowed to perform any actions that adversely affect other applications, systems or users by default. If your app needs to do something, you need to declare the permissions that are used for that operation. (add <uses-permission> tag in manifest file)

The Android system provides a set of permissions that allow you to view Android permissions, and in addition, Android will add some permission to the new version to view Android version information.

Of course, apps can also customize their own permission or permission that belong to the same signature that the developer uses. Defining a permission is to add a permission tag to the Menifest file.

<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"]/>

Android:description: The description of permissions, generally two sentences, the first sentence describes the operation of this permission, the second sentence tells the user to grant the app this permission will bring the consequences
Android:label: A short description of the permissions
Android:name: A unique identifier for permissions, usually using the registration plus permission name
Android:permissiongroup: The name of the permission group to which the permission belongs
Android:protectionlevel: Level of authority,
Normal is the lowest level, the app that declares the sub-permission, the system will grant the second permission by default, will not prompt the user
The dangerous permission corresponds to a security risk, and the system will prompt the user when installing an app that declares such permissions
Signature permission indicates that the operation is only open for apps signed with the same certificate
Signatureorsystem is similar to signature, but adds a claim to the app that comes with the ROM

The Android:name property is required, and other optional, non-writable systems specify default values

The following experiment is done by specifying a broadcastreceiver permission
First created two App,app a, app B;
App A has registered a broadcastreceiver, app B sends a message
App A's menifest file:

<manifest xmlns:android= "http://schemas.android.com/apk/res/android" package= "Com.example.testbutton" Android: Versioncode= "1" android:versionname= "1.0" > <uses-sdk android:minsdkversion= "7" ANDROID:TARGETSD Kversion= "/> <!--claims rights--<permission android:name=" Com.example.testbutton.RECEIVE "/> <ap Plication android:icon= "@drawable/ic_launcher" android:label= "@string/app_name" Android:theme= "@style /apptheme "> <activity android:name=".            Mainactivity "launchemode=" Singletask "android:configchanges=" Locale|orientation|keyboardhidden " android:screenorientation= "Portrait" android:theme= "@style/android:style/theme.notitlebar.fullscreen" &            Gt <intent-filter> <action android:name= "Android.intent.action.MAIN"/> <categor Y android:name= "Android.intent.category.LAUNCHER"/> </Intent-filter> </activity> <!--register broadcast receiver and specify the permissions required to send the message to the current receiver--&lt Receiver Android:name= "Com.example.testbutton.TestButtonReceiver" android:permission= "com.example.t Estbutton. RECEIVE "> <intent-filter> <action android:name=" Com.test.action "/> & Lt;/intent-filter> </receiver> </application></manifest>

App B's menifest file contents

<manifest xmlns:android= "Http://schemas.android.com/apk/res/android" Package= "Com.example.testsender" android:versioncode= "1" android:versionname= "1.0" > <uses-sdk Andro id:minsdkversion= "7" android:targetsdkversion= "/>" <!--declaration using the specified permissions--<uses-permission Android : Name= "Com.example.testbutton.RECEIVE"/> <application android:icon= "@drawable/ic_launcher" Android : label= "@string/app_name" android:theme= "@style/apptheme" > <activity android:name= ".                Mainactivity "android:label=" @string/title_activity_main "> <intent-filter> <action android:name= "Android.intent.action.MAIN"/> <category android:name= "Android.intent.catego Ry. LAUNCHER "/> </intent-filter> </activity> </application></manifest> 

So that app B sends a message to app A, a can be received, if not in app B's menifest file to declare the use of the appropriate permissions, App B sends the message, a is not received.

In addition, you can also add android:protectionlevel= "signature" When declaring permissions in App B's Menifest file, specifying that app B can only receive messages sent by apps signed with the same certificate.

Android Custom Permissions (<permission> <uses-permission>)

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.