Android RxPermissions 动态权限申请
程序员文章站
2022-05-10 11:03:31
...
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
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.arthenica.mobileffmpeg">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:supportsRtl="true"
android:theme="@style/AppTheme"/>
</manifest>
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<Boolean>() {
@Override
public void accept(Boolean aBoolean) throws Exception {
if (aBoolean){
Log.e(TAG, "获取权限成功" );
}else {
Log.e(TAG, "获取权限失败" );
}
}
});
上一篇: Flutter动态权限申请教程