Resolve Android claims and permissions

Android defines a permission scheme to protect resources and functions on the device. For example, by default, applications cannot access contact lists, make calls, and so on. Let's take making a call as an example to introduce the permission requirements of the system. Generally, in our application, if the function of making a call is used, we will code it as follows:

By default, we do not have permission to access the calling activity. The console will report the following exception information:

It seems that we lack call_ The permission of phone is defined in the phone application of Android system:

To use this function, you must declare this permission in our androidmanifest.xml file:

This tells the system that our application uses this permission and we have access to the activity making the call.

We should not only ask, why is the system designed like this? The answer is to protect the security of user resources. To use this function, you must declare permission information in the application. In this way, when the user installs this application, the system will extract permission information from the application, tell the user what functions the application uses, and judge whether the application damages his own security.

Next, let me demonstrate the definition and use of permissions. We establish a phone project. The project structure is as follows:

Let's first look at the code of mainactivity and phoneactivity: mainactivity.java is as follows:

Phoneactivity.java is as follows:

The most important is the androidmanifest.xml file. All our permission statement configurations are completed in this file:

It should be noted that when declaring permissions, you need an Android: protectionlevel attribute, which represents "risk level". Must be one of the following values: normal, dangerous, signature, signatureorsystem.

The other is the Android: permissiongroup attribute, which represents a permission group. You can put permissions in a group, but for custom permissions, you should avoid setting this property. If you really want to set this property, you can use the following property instead: android.permission-group.system_ TOOLS。

Below are screenshots of two activities:

We put a button in mainactivity and click it to jump to phoneactivity of phone application. The mainactivity.java code is as follows:

Then we need to configure the corresponding permissions in the androidmanifest.xml file:

Click the button to jump to phoneactivity smoothly. The screenshot is as follows:

@H_ 403_ 110@

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>