Android6.0 permission management

Source: Internet
Author: User

Android6.0 permission management

Android 6.0 permission Mallow is added to the runtime permission management for the first time. This allows users to better understand and control the permissions involved in the app. However, it is a tough task for developers to adapt to and ensure the normal operation of program functions.
What is runtime permission management? In Android 6.0 or lower systems, when we install an application, the application will prompt us the permissions required for this application. If you want to install the application, you must agree to grant all permissions, but if you do not agree, you can only cancel the installation. You cannot revoke this permission after installation.
In 6.0, the runtime permission is managed. Even if the permission is granted during installation, you can go to the system settings to disable the permission.
In the following situations, the runtime permission is available only for mobile phone versions of Android 6.0 and later. Therefore, we only consider mobile phones with a device version greater, A mobile phone of a lower version has been granted all permissions during installation, and it cannot be withdrawn. In this case, only targetSdkVersion is used:

When the targetSDKVersion is greater than or equal to 23, the permission can be recycled (revoke). Here, the permission is divided into two types: normal permission, the other is dangerous permission. Normal permission is a permission that is irrelevant to the user's privacy and can be understood as an irrelevant permission. For example, the permission to access the network does not matter to the user; dangerous permission involves the user's privacy permissions, such as reading users' mobile phone contacts and text messages. If the permission is normal permission, the permission will be assigned during installation, and the interface will not be opened for the user to revoke the permission. The app will always have this permission, so you do not need to consider this type of permission. If it is dangerous permission, no permissions are granted during installation. The system open interface allows users to revoke or grant permissions. The following figure shows the permissions of an application. The first figure is dangerous permission, which can be recycled and assigned.

Click All permissions above to view all permissions of the application.

Therefore, before using dangerous permission, you must check whether the permission has been granted
checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED

If the permission has been granted, you can continue to execute your code. If not, you need to ask the user if you want to grant the permission. the pop-up box is the system interface, the interface is as follows:

Call code:

requestPermissions(new String[]{Manifest.permission.READ_PHONE_STATE}, 1);

When the system asks whether to grant the permission to the page, a callback is triggered.

@ Overridepublic void onRequestPermissionsResult (int requestCode, String [] permissions, int [] grantResults) {super. onRequestPermissionsResult (requestCode, permissions, grantResults); if (requestCode = 1) {if (grantResults [0] = PackageManager. PERMISSION_GRANTED) {// your implementations} else {ToastUtil. show (this, "insufficient permissions, payment failed ");}}}
If targetSdkVersion is less than 23, the app is not tested with the new 23 permission, and the old rule will be used: the system will assign all permissions to the app by default during installation, the app can run as usual. But! But! But! You can still revoke permissions. Let's take a look at the page that appears when the permission is disabled:

If targetSDKVersion is less than 23, a warning box will pop up when the permission is disabled to tell you that this is an old android version. If you press deny, this permission will be disabled, and the permission switch will be disabled on the interface, but this permission has not been revoked (nexus 5x mobile phone test, of course I do not dare to pack tickets for other hosts ). For example, if the targetSDKVersion of my old app is less than 23, run the app on the 6.0 mobile phone, disable the permission in the settings, and re-run the app, it is found that it will not crash. When running to checkSelfPermission, it is found that a permission has been disabled, but this function returns a message indicating that the permission has been granted. Isn't that a ghost, this permission can also be used properly. I searched the internet. This is a lot of cases, but the people on the Internet are different. Some of them are disabled, and checkSelfPermission returns granted, but an exception is thrown when the permission is used.
Some people later said that the system log is read. I have read it. If targetSDKVersion is 23, the system log is:
Authorization + authorization + u7nT0L7NysfIqM/authorization/tMjnz8LNvKO6PGJyIC8 + DQo8aW1nIGFsdD0 = "here write picture description" src = "http://www.bkjia.com/uploads/allimg/160403/041934B51-5.png" title = ""/>
If one of the groups is granted, the group is also granted by default.

You can also apply for Multiple permissions at the same time.

The following is the URL of the stackoverflow issue:
Http://stackoverflow.com/questions/36328151/ive-revoke-the-android-permission-but-checkselfpermission-still-return-granted

In case of any problems or errors, please point out.

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.