如何知道用户检查“不再询问"在调用 requestPermissions 之前 [英] How to know user check "Never ask again" before calling requestPermissions

查看:35
本文介绍了如何知道用户检查“不再询问"在调用 requestPermissions 之前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,如何在调用 requestPermissions 之前知道用户检查不再询问".

我经历了

当用户勾选回复我明确时,如果尚未授予权限,我将执行requestPermissions.可能有 3 种可能的结果.

第一个结果.第一次调用 requestPermissions 时发生

第二个结果.在第二次或更多次调用 requestPermissions 时发生

第三个结果.当用户勾选不再询问"时发生

不会显示任何对话框.requestPermissions 永远不会弹出任何对话框.我需要代表用户取消选中复选框,因为 onRequestPermissionsResult 会告诉我权限被拒绝.

第三个结果会产生糟糕的用户体验.当用户勾选复选框时,它将立即取消勾选.

我想在显示反馈表单之前隐藏回复我.为此,我需要知道用户是否已经选中不再询问".

shouldShowRequestPermissionRationale 没有多大帮助.因为,shouldShowRequestPermissionRationale 会在两种情况下返回 false

  1. 用户已勾选不再询问".
  2. requestPermissions 以前从未被调用过.

我找不到区分两者的方法.

解决方案

当你请求许可时,保存一个布尔值 共享偏好 为真.然后,您将能够检查它的值以了解您是否已经请求许可,并知道 shouldShowRequestPermissionRationale() 是否返回 false 是因为您以前从未询问过或因为他们再也没有说过或者因为设备策略禁用了该权限.

I was wondering, how to know user check "Never ask again" before calling requestPermissions.

I had gone through Android M - check runtime permission - how to determine if the user checked "Never ask again"? but can't get a proper solution yet.

Before that, please allow me to explain my motive.

I have the following feedback dialog form.

When user tick on Reply to me explicitly, I will perform requestPermissions if permissions is not granted yet. There can be 3 possible outcome.

1st outcome. Happens when calling requestPermissions for 1st time

2nd outcome. Happens when calling requestPermissions for 2nd, or more time

3rd outcome. Happens when user has ticked "Never ask again"

No dialog will be shown. requestPermissions will never pop up any dialog. I need untick the checkbox on behalf of user, as onRequestPermissionsResult will tell me permission is denied.

3rd outcome will produce bad user experience. As when user tick on the checkbox, it will become untick immediately.

I would like to hide Reply to me before making feedback form visible. To do this, I need to know whether user has already check "Never ask again".

shouldShowRequestPermissionRationale doesn't help much. As, shouldShowRequestPermissionRationale will return false in 2 cases

  1. User has already check "Never ask again".
  2. requestPermissions is never called before.

I don't find a way to differentiate between both.

解决方案

When you ask for permission, save a boolean shared preference as true. You'll then be able to check the value of that to know if you have already asked for permission and know if shouldShowRequestPermissionRationale() is returning false because you've never asked before or because they said never again or because the permission is disabled by device policy.

这篇关于如何知道用户检查“不再询问"在调用 requestPermissions 之前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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