android rx申请权限,Android RxPermissions 动态权限申请

RxPermissions 动态权限申请

https://github.com/tbruyelle/RxPermissions

Project

allprojects {

repositories {

google()

jcenter()

maven { url 'https://jitpack.io' }

}

}

Module

def rxjava_version = "2.0.1"

//RxJava的依赖包

implementation 'io.reactivex.rxjava2:rxjava:' + rxjava_version

//RxAndroid的依赖包

implementation 'io.reactivex.rxjava2:rxandroid:' + rxjava_version

//权限

implementation 'com.github.tbruyelle:rxpermissions:0.10.2'

AndroidManifest

package="com.arthenica.mobileffmpeg">

android:supportsRtl="true"

android:theme="@style/AppTheme"/>

MainActivity

final RxPermissions rxPermissions = new RxPermissions(this); // where this is an Activity or Fragment instance

rxPermissions

.request(Manifest.permission.READ_EXTERNAL_STORAGE,

Manifest.permission.WRITE_EXTERNAL_STORAGE)

.subscribe(new Consumer() {

@Override

public void accept(Boolean aBoolean) throws Exception {

if (aBoolean){

Log.e(TAG, "获取权限成功" );

}else {

Log.e(TAG, "获取权限失败" );

}

}

});

你可能感兴趣的:(android,rx申请权限)