如何区分用户是第一次请求权限还是点击了“不再询问”按钮?
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) {
// In an educational UI, explain to the user why your app requires this
// permission for a specific feature to behave as expected. In this UI,
// include a "cancel" or "no thanks" button that allows the user to
// continue using your app without granting the permission.
} else {
if (requireContext().checkSelfPermission(Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED)
openCamera();
else {
//How can I know here if this is was the first time to request the permission or he pressed on Never Ask Again button before?
//Run this code if that was the first time to request the permission -> requestPermissionLauncher.launch(Manifest.permission.CAMERA);
//Run this code if he pressed on Never Ask Again button -> new AlertDialog(context)... etc - The dialog contains a button that moves the user to app settings to enable the permission
}
}
} else
openCamera();
如何区分用户是第一次请求权限还是点击了“不再询问”按钮?
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) {
// In an educational UI, explain to the user why your app requires this
// permission for a specific feature to behave as expected. In this UI,
// include a "cancel" or "no thanks" button that allows the user to
// continue using your app without granting the permission.
} else {
if (requireContext().checkSelfPermission(Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED)
openCamera();
else {
//How can I know here if this is was the first time to request the permission or he pressed on Never Ask Again button before?
//Run this code if that was the first time to request the permission -> requestPermissionLauncher.launch(Manifest.permission.CAMERA);
//Run this code if he pressed on Never Ask Again button -> new AlertDialog(context)... etc - The dialog contains a button that moves the user to app settings to enable the permission
}
}
} else
openCamera();
How can I distinguish if the user request the permission for the first time or he clicked on the Never Ask Again button?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
布尔值可用于检查用户是否先前拒绝了权限。
将以下方法添加到上述文件或创建实用程序文件。
权限请求地方里面调用:
A
boolean
value can be used to check if the user has denied permission earlier or not.Add the following methods to the above file or create a utility file.
Call inside the permission Request place: