Android 6.0 multiple permissions

后端 未结 22 2383
太阳男子
太阳男子 2020-11-22 03:58

I know that Android 6.0 has new permissions and I know I can call them with something like this

if (ContextCompat.checkSelfPermission(this, Manifest.permiss         


        
22条回答
  •  梦谈多话
    2020-11-22 04:39

    After seeing all the long and complex answers. I want post this answer.

    RxPermission is widely used library now for asking permission in one line code.

    RxPermissions rxPermissions = new RxPermissions(this);
    rxPermissions
    .request(Manifest.permission.CAMERA,
             Manifest.permission.READ_PHONE_STATE)
    .subscribe(granted -> {
        if (granted) {
           // All requested permissions are granted
        } else {
           // At least one permission is denied
        }
    });
    

    add 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'
    }
    

    Isn't this easy?

提交回复
热议问题