In front of the Android6.0 permission description and permissions of a single, multiple applications, using pure Java code, this article is mainly about the use of third-party libraries to implement permission applications.
Use the third-party library easypermissions to apply for 6.0 permissions, which Google has officially recommended.
easypermissions Library Address:https://github.com/googlesamples/ Easypermissions
Bulid.gradle introduced:
' pub.devrel:easypermissions:1.0.0 '
Permission related knowledge, permission table please read the blog:
Android6.0------Rights Management
Android6.0------Permission Request Management (single permission and multiple permission requests)
Android6.0------Permission Application Rxpermissions
Premise: The app is running on Android 6.0 (API level 23)
a higher-level device, and the targetSdkVersion>=23
system will automatically adopt a dynamic rights management policy,
First Take a look: ( Note: If not authorized to click on the phone or take a photo will be directly back, so 6.0 must be manually authorized, development if not authorized, you can judge and prompt the user from the new authorization )
Cases mainly have phone, SD card, photo authorization three authorized together
Use an array to put the permissions you want to apply together, and then apply
String[] perms = {Manifest.permission.CAMERA, Manifest.permission.write_external_storage,manifest.permission.call_ PHONE};
Request Permission Code:
Private voidmethodrequirestwopermission () {string[] perms={Manifest.permission.CAMERA, manifest.permission.write_external_storage,manifest.permission.call_phone}; if(Easypermissions.haspermissions ( This, perms)) {//check whether to get this permissionToast.maketext (mainactivity. This, "Permission has been acquired", Toast.length_long). Show (); } Else { //The second parameter is an explanation of the permission being rejected after the request//The third parameter is the request code//The fourth parameter is the permission to applyEasypermissions.requestpermissions ( This, "Get Permissions", Rc_camera_and_location, perms); } }
//Receive permission processing result @Override Public voidOnrequestpermissionsresult (intRequestcode, @NonNull string[] permissions, @NonNullint[] grantresults) { Super. Onrequestpermissionsresult (Requestcode, permissions, grantresults); //Handing over the callback of the application authority to easypermissionsEasypermissions.onrequestpermissionsresult (Requestcode, permissions, Grantresults, This); } @Override Public voidOnpermissionsgranted (intRequestcode, list<string>perms) {LOG.I ("TAG", "Get Successful permissions:" +perms); Toast.maketext (mainactivity. This, "Get permission succeeded", Toast.length_long). Show (); } @Override Public voidOnpermissionsdenied (intRequestcode, list<string>perms) {Toast.maketext (mainactivity). This, "No permissions acquired" +Perms,toast.length_long). Show (); }
The premise must be noted: Androidmanifest:
<Uses-permissionAndroid:name= "Android.permission.CALL_PHONE"/> // phone <uses-permission android:name= "Android.permission.CAMERA"/> // photo <uses-permission android:name= "Android.permission.WRITE_EXTERNAL_ STORAGE "/> //SD card
This case is written by Google's recommended third-party easypermissions, and you can look at the library's code.
Case Source Download
Android6.0------Permission Application ~easypermissions