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 rxpermissions to request 6.0 permissions.
rxpermissions Library Address:https://github.com/tbruyelle/RxPermissions
Bulid.gradle introduced:
compile' com.tbruyelle.rxpermissions2:rxpermissions:[email protected] ' compile "io.reactivex.rxjava2:rxjava:2.0.0"
Permission related knowledge, permission table See blog: Android6.0------Rights Management Android6.0------Permission Request Management (single permission and multiple permission requests)
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 )
:
1: Single authorization, phone authorization.
2: There is a phone, SD card, photo authorization three together authorized
Individual authorizations
//Check if version is greater than M if(Build.VERSION.SDK_INT >=Build.version_codes. M) {//Individual Permissionsrxpermissions.request (Manifest.permission.CAMERA). Subscribe (NewObserver<boolean>() {@Override Public voidOnsubscribe (disposable d) {} @Override Public voidOnNext (Boolean value) {if(value) {Showtoast ("Consent Permission"); }Else{showtoast ("Deny permission"); }} @Override Public voidOnError (Throwable e) {} @Override Public voidOnComplete () {}}); }
Multiple authorizations
Rxpermissions.requesteach (Manifest.permission.camera,manifest.permission.write_external_storage, Manifest.permission.CALL_PHONE). Subscribe (NewObserver<permission>() {@Override Public voidOnsubscribe (disposable d) {} @Override Public voidOnNext (Permission Permission) {if(Permission.name.equals (Manifest.permission.CAMERA)) {Showtoast ("Successful Application"); }} @Override Public voidOnError (Throwable e) {} @Override /c4> Public voidOnComplete () {}});
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 with the help of a third-party rxpermissions, so you can look at the code for this library.
Case Source Download
Android6.0------Permission Application Rxpermissions