Rxpermissions

该库允许将 RxJava 与新的 Android M 权限模型一起使用。

将库添加到依赖项:

Rxjava

dependencies {
    compile 'com.tbruyelle.rxpermissions:rxpermissions:0.8.0@aar'
}

Rxjava2

dependencies {
    compile 'com.tbruyelle.rxpermissions2:rxpermissions:0.8.1@aar'
}

用法

示例(为了简洁起见,使用 Retrolambda,但不是必需的):

// Must be done during an initialization phase like onCreate
RxPermissions.getInstance(this)
    .request(Manifest.permission.CAMERA)
    .subscribe(granted -> {
        if (granted) { // Always true pre-M
           // I can control the camera now
        } else {
           // Oups permission denied
        }
    });

阅读更多: https//github.com/tbruyelle/RxPermissions