Android marshmallow request permission?

后端 未结 24 2123
無奈伤痛
無奈伤痛 2020-11-21 06:40

I am currently working on an application that requires several \"dangerous\" permissions. So I tried adding \"ask for permission\" as required in Android Marshmallow(API Lev

24条回答
  •  自闭症患者
    2020-11-21 07:16

    I use RxPermission library library for asking permission. Because it is long code which we have to write to ask permission.

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

    Add these dependency 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'
    }
    

提交回复
热议问题