Hello, I am here again after a long break. I had a busy period so I couldn't share anything. There is a lot to tell but I have to start from somewhere. So the topic, I am going to tell you today is RxPermissions 🙂
What is RxPermissions?
Answer : Android runtime permissions powered by RxJava2
This library allows the usage of RxJava with the new Android M permission model.
How to use that?
First we need to add some these permissions (or whatever we need) in our manifest.xml
.
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
add this library in your build.gradle
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.tbruyelle:rxpermissions:0.10.1'
implementation 'com.jakewharton.rxbinding2:rxbinding:2.1.1'
}
Then we ask runtime permission from user in our activity.
RxPermissions rxPermissions = new RxPermissions(this);
rxPermissions
.request(Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION) // ask single or multiple permission once
.subscribe(granted -> {
if (granted) {
// All requested permissions are granted
} else {
// At least one permission is denied
}
});
rxPermissions .request(Manifest.permission.CAMERA, Manifest.permission.READ_PHONE_STATE, Manifest.permission.ACCESS_COARSE_LOCATION) .subscribe(granted -> { if (granted) { // All requested permissions are granted } else { // At least one permission is denied } });
is it not easy? Take advantage of the blessings of Rxjava 🙂
You can find this library on this link and have more informations about that.