Android 6.0 Open failed:eacces (Permission denied)
For 6.0+ permissions problem, the error is as above:
Solution:
Android 6.0 (Marshmallow). Adding a new permission model requires that you dynamically obtain the required permissions at run time.
First, determine whether the phone system version is 6.0+ and then the support runtime to obtain permissions dynamically:
Private Boolean canmakesmores () { return(build.version.sdk_int>build.version_codes. LOLLIPOP_MR1);}
Then, the operation gets permissions:
String[] perms = {"Android.permission.RECORD_AUDIO","Android.permission.CAMERA"};intPermsrequestcode = $; Requestpermissions (perms, permsrequestcode); Requestpermissions This method is the activity method, And then get the callback result of the permission grant in Onrequestpermissionresult: @Override Public voidOnrequestpermissionsresult (intPermsrequestcode, string[] permissions,int[] grantresults) { Switch(permsrequestcode) { Case $: Boolean audioaccepted= grantresults[0]==packagemanager.permission_granted; Boolean cameraaccepted= grantresults[1]==packagemanager.permission_granted; Break; }}
The following method can be used to obtain whether the user has granted some special privileges:
Private Boolean haspermission (String permission) { if (Canmakesmores ()) { return (checkselfpermission ( permission) ==packagemanager.permission_granted); } return true;}
If the user has authorized these permissions, the system will not remember, we need to remember these.
Private Boolean Shouldweask (String permission) { return (Sharedpreferences.getboolean (permission, True));} private void markasasked (String permission) { sharedpreferences.edit (). Putboolean (permission, false). Apply;}
The same page, you may need some permissions several times, remember not to let the user authorize repeatedly
Private ArrayList Findunaskedpermissions (ArrayList wanted) { ArrayList result = new arraylist<~> (); for (String perm:wanted) { if (!haspermission (perm) && Shouldweask (perm)) { result.add (perm); } } return result;}
Transferred from: http://www.captechconsulting.com/blogs/ Runtime-permissions-best-practices-and-how-to-gracefully-handle-permission-removal
Android 6.0 Permissions Issue