Android之RxPermissions用kotlin写没反应

1 问题

用rxPermisssons下面的写法没反应

    @RequiresApi(Build.VERSION_CODES.N)
    fun test(){
        val rxPermissions = RxPermissions(this)
        rxPermissions.requestEach(
            Manifest.permission.CAMERA,
            Manifest.permission.WRITE_EXTERNAL_STORAGE
        ).subscribe {
            object : Consumer{
            override fun accept(t: Permission) {
                if(t.granted) {
                    
                }
            }
        }
    }

 

 

 

 

 

 

 

2 解决办法

不要object,直接调

    @RequiresApi(Build.VERSION_CODES.N)
        fun test(){
            val rxPermissions = RxPermissions(this)
            rxPermissions.requestEach(
                Manifest.permission.CAMERA,
                Manifest.permission.WRITE_EXTERNAL_STORAGE
            ).subscribe {
                if (it.granted) {
                }
            }
        }

 

 

 

 

 

 

 

3 所有权限只回调结果一次这样写

    @RequiresApi(Build.VERSION_CODES.N)
    fun test(){
        val rxPermissions = RxPermissions(this)
        rxPermissions.requestEach(
            Manifest.permission.CAMERA,
            Manifest.permission.WRITE_EXTERNAL_STORAGE
        ).subscribe {
            object : Consumer{
            override fun accept(t: Permission) {
                if(t.granted) {
                    
                }
            }
        }
    }

 

你可能感兴趣的:(android)