简体   繁体   English

权限对话框未显示在 android 中

[英]Permission dialog is not showing in android

I am using Dexter library for camera permission in my app.When user clicks on button I want to check permission but when I am clicking on button no permission is checked.我在我的应用程序中使用Dexter 库获取相机权限。当用户点击按钮时,我想检查权限,但是当我点击按钮时,没有检查权限。 Below is my code:下面是我的代码:

class MainActivity : AppCompatActivity(), PermissionListener {
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    choose.setOnClickListener {
        Toast.makeText(applicationContext,"HEllo",Toast.LENGTH_SHORT).show();
        Dexter.withActivity(this)
            .withPermission(android.Manifest.permission.CAMERA)
            .withListener(this)
    }
}

override fun onPermissionGranted(response: PermissionGrantedResponse?) {
    Toast.makeText(applicationContext,"Granted",Toast.LENGTH_SHORT).show();
}

override fun onPermissionRationaleShouldBeShown(
    permission: PermissionRequest?,
    token: PermissionToken?
) {

}

override fun onPermissionDenied(response: PermissionDeniedResponse?) {
    Toast.makeText(applicationContext,"Denied",Toast.LENGTH_SHORT).show();
}
}  

Someone please let me know what I am doing wrong.Any help would be appreciated.有人请让我知道我做错了什么。任何帮助将不胜感激。

THANKS谢谢

I am using Dexter library for camera permission in my app.When user clicks on button I want to check permission but when I am clicking on button no permission is checked.我在我的应用程序中使用Dexter库获取相机权限。当用户单击按钮时,我要检查权限,但是当我单击按钮时,未检查权限。 Below is my code:下面是我的代码:

class MainActivity : AppCompatActivity(), PermissionListener {
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    choose.setOnClickListener {
        Toast.makeText(applicationContext,"HEllo",Toast.LENGTH_SHORT).show();
        Dexter.withActivity(this)
            .withPermission(android.Manifest.permission.CAMERA)
            .withListener(this)
    }
}

override fun onPermissionGranted(response: PermissionGrantedResponse?) {
    Toast.makeText(applicationContext,"Granted",Toast.LENGTH_SHORT).show();
}

override fun onPermissionRationaleShouldBeShown(
    permission: PermissionRequest?,
    token: PermissionToken?
) {

}

override fun onPermissionDenied(response: PermissionDeniedResponse?) {
    Toast.makeText(applicationContext,"Denied",Toast.LENGTH_SHORT).show();
}
}  

Someone please let me know what I am doing wrong.Any help would be appreciated.有人请让我知道我在做什么错,任何帮助将不胜感激。

THANKS谢谢

You need to call .check() while requesting the permission您需要在请求权限时调用 .check()

Dexter.withActivity(this)
            .withPermission(android.Manifest.permission.CAMERA)
            .withListener(this).check()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM