Android APK and apk communicate with each other--How to customize permissions

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 tags to the 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.


1 <permission android:description= "string resource"
2 android:icon= "drawable resource"
3 android:label= "string resource"
4 Android:name= "string"
5 android:permissiongroup= "string"
6 android:protectionlevel=["Normal" | "Dangerous" | " Signature "| "Signatureorsystem"]/>
7
Here is a brief description of each parameter:


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:


1 <manifest xmlns:android= "Http://schemas.android.com/apk/res/android"
2 package= "Com.example.testbutton"
3 android:versioncode= "1"
4 Android:versionname= "1.0" >
5 <uses-sdk android:minsdkversion= "7" android:targetsdkversion= "/>"
6 <!--claim permissions--
7 <permission android:name= "Com.example.testbutton.RECEIVE"/>
8 <application
9 android:icon= "@drawable/ic_launcher"
Ten 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" >
<intent-filter>
<action android:name= "Android.intent.action.MAIN"/>
<category 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--
<receiver
Android:name= "Com.example.testbutton.TestButtonReceiver"
android:permission= "Com.example.testbutton.RECEIVE" >
<intent-filter>
<action android:name= "Com.test.action"/>
</intent-filter>
</receiver>
</application>
</manifest>
App B's menifest file content


1 <manifest xmlns:android= "Http://schemas.android.com/apk/res/android"
2 package= "Com.example.testsender"
3 android:versioncode= "1"
4 Android:versionname= "1.0" >
5 &LT;USES-SDK
6 android:minsdkversion= "7"
7 android:targetsdkversion= "/>"
8 <!--declaration use the specified permissions--
9 <uses-permission android:name= "Com.example.testbutton.RECEIVE"/>
Ten <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.category.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.


The mutual invocation of data between the two Android apps is an issue that we often encounter, and this article focuses on the Android development Customization permission issue that I hope will help the vast number of Android developers.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android APK and apk communicate with each other--How to customize permissions

Related Article

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.