You can use RxPermissions to simplify the flow for permission handling. Below are the some code snippet for Rx that you can directly use.
RxPermissions rxPermissions = new RxPermissions(this); // where this is an Activity instance
rxPermissions
.requestEach(Manifest.permission.READ_PHONE_STATE, Manifest.permission.READ_SMS , Manifest.permission.READ_PHONE_NUMBERS)
.subscribe(permission -> { // will emit 3 Permission objects
if (permission.granted) {
// `permission.name` is granted !
} else if (permission.shouldShowRequestPermissionRationale) {
// Denied permission without ask never again
} else {
// Denied permission with ask never again
// Need to go to the settings for this.
}
});
You can use above code snippet to efficiently manage permission model in your project.
Also, for quick integration just add below lines in build.gradle of your module along with above code snippet.
//RxAndroid
implementation "io.reactivex.rxjava2:rxandroid:${libraries.rxAndroid}"
// RxJava
implementation "io.reactivex.rxjava2:rxjava:${libraries.rxjava2}"
//RXpermissions
implementation 'com.tbruyelle.rxpermissions2:rxpermissions:0.8.1@aar'
Full integration of RxPermission you can refer to
- Rx Permission