Android M-无论如何要知道用户是否选择了再也不显示授予权限对话框? [英] Android M - anyway to know if a user has chosen never to show the grant permissions dialog ever again?

查看:411
本文介绍了Android M-无论如何要知道用户是否选择了再也不显示授予权限对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果所有人都调用ActivityCompat.requestPermissions(),则操作系统会显示一个带有拒绝"或允许"按钮的对话框.还有一个永不再显示此复选框.

If an all calls ActivityCompat.requestPermissions() then the OS displays a dialog with Deny or Permit buttons. There is also a never show this again tick box.

但是,我无法看到应用程序是否知道用户是否已勾选了此框-在onRequestPermissionsResult()中,如果用户单击拒绝",并且如果用户在单击拒绝"之前选中了复选框,则GrantResults参数为PERMISSION_DENIED . 那么,是否有应用程序可以找出用户是否不想再次看到该对话框?

However there's no way that I can see for the app to know if the user has ticked this box - within onRequestPermissionsResult() the grantResults parameter is PERMISSION_DENIED if the user clicks Deny and also if the user ticks the tick box before clicking Deny. So is there anyway an app can find out if the user doesn't want to see that dialog again?

推荐答案

您可以使用

You can use ActivityCompat.shouldShowRequestPermissionRationale() - it will return false in a few cases:

  • 您之前从未申请过许可
  • 用户已选中永不再"复选框
  • 该权限已被政策停用(例如在工作中)

通过将其与共享的首选项结合起来存储(如果您曾经请求过许可),可以有效地确定他们在调用requestPermissions()时是否真的会看到对话框.

By combining this with a shared preference to store if you've ever asked for permission, you can effectively determine if they'll actually see the dialog when you call requestPermissions().

这篇关于Android M-无论如何要知道用户是否选择了再也不显示授予权限对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆