Android M (6.0) Privilege Crawl Pit Tour

Source: Internet
Author: User

Pit one: With Android5.0 compiled APK, run on Android6.0 completely no problem.
    1. You need to request permissions at run time over Android6.0, leave the original logic on the old Android version, and grant permissions when you install.
    2. The old version of the SDK compiled APK, both use the old version of permissions, the installation to grant permissions. (That is, older versions are compatible)
    3. Compiling the APK with Android6.0 (targetsdkversion 23) requires handling the new permissions issue.
    4. There is an egg ache problem: In the program running, the user closed the permissions, what happens? (also unknown)
Pit Two: Bluetooth scan requires location permissions
Bluetoothutils:permission denial:need access_coarse_location or access_fine_location Permission to get scan results
How to apply for a permission: Raise chestnuts with access_coarse_location 1. Manifest Adding permissions

Android6.0 several permissions: Normal Permissions (Automatic authorization at installation, user cannot cancel permission) anddangerous Permissions

    <!--Android6.0 Bluetooth scanning is required-    <uses-permission-sdk-23 android:name= "android.permission.ACCESS_COARSE_ Location "/>
2. Request permission
Determine if there is permission//here, Thisactivity is the current activityif (Contextcompat.checkselfpermission (thisactivity,                Manifest.permission.ACCESS_COARSE_LOCATION)!        = packagemanager.permission_granted)// Request Permission Activitycompat.requestpermissions (thisactivity,                new string[]{manifest.permission.access_coarse_location },                my_permissions_request_access_coarse_location);//Determine if you need to explain to the user, Why to apply for this permission Activitycompat.shouldshowrequestpermissionrationale (thisactivity,                Manifest.permission.READ_ CONTACTS)//Permission application result onrequestpermissionsresult (int requestcode,        String permissions[], int[] grantresults)
Pit Three: Fragment request permission
If you use Activitycompat.requestpermissions, you will not call Onrequestpermissionsresult ()//Request permission requestpermissions (new String[]{ Manifest.permission.ACCESS_COARSE_LOCATION},                my_permissions_request_access_coarse_location);//Determine if you need to explain to the user, Why to apply for this permission Shouldshowrequestpermissionrationale (Manifest.permission.READ_CONTACTS)
Pit Four: Write_settings permissions how to deal with

Android.permission.WRITE_SETTINGS can not be automatically authorized, and can not be run when the request authorization, why the whole ah? Let the user set up by opening intent. Seemingly settings permission can only be handled so, from CommonsWare the Android 6.0 changes.

    /** * An app can use this method to check if it's currently allowed to write or modify system * settings. In order to gain write access to the system settings, an app must declare the * {@link Android. Manifest.permission#write_settings} permission in its Manifest. If It is * currently disallowed, it can prompt the user to grant it this capability through a * management UI by S     Ending an Intent with action * {@link android.provider.settings#action_manage_write_settings}. * * @param context A Context * @return True if the calling app can write to system settings, FALSE otherwise * /if (!                    Settings.System.canWrite (This)) {Intent Intent = new Intent (settings.action_manage_write_settings,          Uri.parse ("Package:" + getpackagename ()));     Startactivityforresult (Intent, Request_code); } @Override protected void Onactivityresult (int requestcode, int resultcode, Intent data) {if (Requestcode = = REQUEST_code) {if (Settings.System.canWrite (this)) {//Check returns the result Toast.maketext (mainactivi            Ty.this, "write_settings permission granted", Toast.length_short). Show (); } else {Toast.maketext (mainactivity.this, "write_settings permission not Granted", Toast.length_short). Sho            W (); }        }    }

From: https://yanlu.me/android-m6-0-permission-chasm/

Android M (6.0) Privilege Crawl Pit Tour

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.