Androidmanifest.xml file Details (uses-permission)

Source: Internet
Author: User

Syntax (SYNTAX):

<uses-permissionandroid:name="string"/>

Included in (CONTAINED in):

<manifest>

Description (DESCRIPTION):

androidmanifest.xml detailed document (iii) "Permissions" in the document ( Span style= "Font-family:microsoft Yahei; font-size:16px; Color: #800080; " >http://blog.csdn.net/fireofstar/article/details/7543067 http:// blog.csdn.net/fireofstar/article/details/7536803 http://developer.android.com/reference/android/Manifest.permission.html ).

Properties (ATTRIBUTES):

Android:name

This property is used to define the name of the permission. It can be a permission defined by the application with the <permission> element, a permission defined by another application, or a system-defined standard of permissions, such as: Android:permission. Camera or Android:permission. Read_contacts and so on. As shown in the example, the permission name is usually prefixed with the package name to ensure its uniqueness.

Introduced version (introduced in):

API Level 1

App Customization <permission>

God, this article finally said how to customize permissions, left hope right, in fact, this custom permission is quite easy. To facilitate the narrative, I will use two apps as an example to illustrate this.

Permission app:used to define a new Permission
This app, which defines permissions, I call the permission app.
Client app:used to access the specified activity of Permission App
As an app that accesses the above custom permissions, I call it the client app

First look at how to write the permission App

The first step

Permission app is simple, its task is to set a Permission, using < permission> tag, we assume the content is as follows:

<permission

Android:name= "Custom.permission.STARTACTIVITY" android:description= "@string/permission_dcr" Android: Protectionlevel=signatureorsystem android:label= "label" ></permission>


Step Two

Then in the activity, the activity is simple to display the next line of words, such as "Hello from Custiom Permission activity!" It is not detailed here.

Step Three

The most important place: we need to specify access rights for this activity, which is the permission we have just requested, which needs to be identified in the Androidmanifest.xml file as follows:

Copy CodeThe code is as follows:


<activity
Android:name= "Com.example.custompermission.MainActivity"
Android:label= "@string/app_name" android:permission= "Custom.permission.STARTACTIVITY" >
</activity>


The activity is then hit with a mark that must be accessed with the "Custom.permission.STARTACTIVITY" permission.

Then write the client App

As for how to write the client App, then so ... easy, just two steps:

The first step

In the Androidmanifest.xml file, first request permission, as follows:

The code is as follows:


<uses-permission android:name= "Custom.permission.STARTACTIVITY"/>


Step Two

Accessing the Permission app indicates that the activity is required for this permission, and the code is as follows:

Intent in = new Intent ();

In.setclassname ("Com.example.custompermission", "com.example.custompermission.MainActivity");
StartActivity (in);

Done

We can test the effect, first install the permission app, then install the client app, the results are as follows:

After clicking

In addition I once mentioned the protection level problem in the Android permission permission mechanism Introduction, this side I also test this protection level, the following result in Y means to be able to access normally, n means not to be accessible.

It is important to note that the activity that uses the custom permission if set

<activity
Android:name= "Com.example.custompermission.MainActivity"
Android:label= "@string/app_name" android:permission= "Custom.permission.STARTACTIVITY" >
<intent-filter>
<action android:name= "Android.intent.action.MAIN"/>
<category android:name= "Android.intent.category.LAUNCHER"/>
</intent-filter>

Then you can't start the app from Launcher, Because only your launcher must use Uses-permission to request Custom.permission.STARTACTIVITY permission, in fact your launcher does not have the custom permission already requested.

Launcher: Application is not installed on your phone. The error.

Androidmanifest.xml file Details (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.