Android6.0 Rights Management

Source: Internet
Author: User

Android 6.0 Marshmallow first joined runtime Rights Management, which gives users a better understanding and control over the permissions that the app involves. However, for developers, it is a more painful thing, need compatibility, and ensure the normal operation of the program function.
What is runtime Rights management? In the Android 6.0 system, when we install the application, the app will prompt us the application of the required permissions, if you want to install, it must agree to give all permissions, but if you do not agree, it can only cancel the installation, a bit rogue. And after installation, you can not revoke this permission.
and 6.0 to do the run-time rights management, even when the installation of the permissions, you can go to the system settings, to turn off this permission.
Here are a few things Because the runtime permissions only in Android6.0 and above the mobile phone version only, so here only consider the device version of more than 6.0 of the phone, the lower version of the phone in the installation has been given all the permissions, it is not possible to take back, it is not considered, the following conditions are only divided targetsdkversion:

    1. Targetsdkversion is greater than or equal to 23, then the permissions can be recycled (revoke), here also to separate permissions, Google will be divided into two kinds of permissions, one is normal permission, the other is dangerous permission. Normal permission refers to the user's privacy is not related to the rights, can be understood as insignificant permissions, such as access to the network permissions, not related to the user; Dangerous permission is a privilege that involves user privacy, such as reading a user's phone contact, SMS and so on. If it is normal permission, then the installation will be given, and will not open the interface for users to reclaim this permission, the app will always have this permission, so do not consider this type of permissions. If it is dangerous permission, when the installation is not granted permission, the system open interface allows users to reclaim or grant permissions. Here is the permission for an app, and the first graph is dangerous permission, which can be recycled and given.

      Click all of the permissions above to see all the permissions for that app.

      So for dangerous permission, it is necessary to check if the permission has been granted before use.
checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED

If this permission has been granted, then you can continue to execute your code, if not granted, you need to ask the user whether to grant permissions, the popup box is the system interface, the interface is as follows:

Calling code:

requestPermissions(newString1);

The system asks if permission is granted when the page ends with a callback

 @Override  public  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 , ); }    }}
    1. If Targetsdkversion is less than 23, then it will be considered that the app has not been tested with 23 new permissions, then continue to use the old rule: the system will be installed by default to the app to give all permissions, the app can run as usual. But! But! But! Users can still reclaim permissions, but this collection is not recycled. Take a look at the page that bounced when the permission was closed:

      See, if targetsdkversion is less than 23, when the permission is closed, will play a warning box, tell you that this is the old version of Android, the shutdown will be a problem, if you press deny, then the permission will be closed, and the interface, the permission switch will show off, But this privilege has not been recycled (Nexus 5x mobile phone pro-test, of course, other machines I do not dare to pack tickets). For example, my old version of App,targetsdkversion is less than 23, Then the app ran on 6.0 of the phone, and in the settings to close the permissions, rerun the app, found that it does not crash, when running to Checkselfpermission, found that a privilege has been closed, but this function returned to tell that the permission was given, this is not a ghost, and this permission can also be used normally. Internet search, this situation is many, but the people on the Internet, some are closed permissions, checkselfpermission return granted, but when using permissions, throws an exception.
      Later someone said to look at the system log, I looked under, if Targetsdkversion equals 23, the system log is:

      If Targetsdkversion is less than 23, then the log is:
      Permission related app op changed.

I've already asked questions on the StackOverflow, but no one has answered, and I haven't found the reason and the official saying, but some people say that targetsdkversion less than 23 apps can only be retrieved by uninstalling the app, which has not been confirmed yet.

But I guess if you want to support runtime permission, you still have to set Targetsdkversion to 23. If your targetsdkversion is less than 23, then still add checkselfpermission, just in case, who knows what Google will be out of the hole.

There is the permission, there is the concept of grouping, see as:

If one of the groups is granted, it is also granted by default in the group.

and also support to apply for multiple permissions at the same time, the specific situation of Android developer official website.

Here is the URL to the StackOverflow question:
http://stackoverflow.com/questions/36328151/ive-revoke-the-android-permission-but-checkselfpermission-still-return-granted

Please state if there are any problems or errors.

Android6.0 Rights Management

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.