Android6.0------Permission Application Rxpermissions

Source: Internet
Author: User

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

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.