在Android M的运行时权限中,我们如何区分永不停止和永不停止? [英] How Do We Distinguish Never-Asked From Stop-Asking in Android M's Runtime Permissions?

查看:83
本文介绍了在Android M的运行时权限中,我们如何区分永不停止和永不停止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于M Developer Preview运行时权限,请根据 Google :

When it comes to the M Developer Preview runtime permissions, according to Google:

  1. 如果您以前从未请求过特定许可,只需提出请求

  1. If you have never asked for a certain permission before, just ask for it

如果您之前询问过,并且用户说否",然后用户尝试执行需要被拒绝的权限的操作,则在继续操作之前,应提示用户解释为什么需要此权限.再次请求许可

If you asked before, and the user said "no", and the user then tries doing something that needs the rejected permission, you should prompt the user to explain why you need the permission, before you go on to request the permission again

如果您之前问过几次,并且用户说了不,并停止询问"(通过运行时权限对话框上的复选框),则应该停止打扰(例如,禁用需要许可)

If you asked a couple of times before, and the user has said "no, and stop asking" (via the checkbox on the runtime permission dialog), you should just stop bothering (e.g., disable the UI that requires the permission)

但是,我们只有一个方法shouldShowRequestPermissionRationale(),它返回一个boolean,并且我们具有三种状态.我们需要一种将永​​不请求状态与永不请求状态区分开的方法,因为我们都从shouldShowRequestPermissionRationale()中获取了false.

However, we only have one method, shouldShowRequestPermissionRationale(), returning a boolean, and we have three states. We need a way to distinguish the never-asked state from the stop-asking state, as we get false from shouldShowRequestPermissionRationale() for both.

对于在首次运行该应用程序时要求的权限,这不是一个大问题.有很多方法可以确定这可能是您应用程序的首次运行(例如,SharedPreferences中的boolean值),因此您假设如果这是应用程序的首次运行,则您永远都不会询问状态.

For permissions being requested on first run of the app, this is not a big problem. There are plenty of recipes for determining that this is probably the first run of your app (e.g., boolean value in SharedPreferences), and so you assume that if it's the first run of your app, you're in the never-asked state.

但是,运行时权限的部分目标是您可能不需要在先要求所有权限.与边缘功能相关联的权限只有在用户点按需要该权限的内容时,才可能在以后请求.在这里,该应用可能已经运行了好几个月,已经运行了好几个月了,然后才突然需要另外的权限.

However, part of the vision of runtime permissions is that you might not ask for all of them up front. Permissions tied to fringe features you might only ask for later on, when the user taps on something that requires that permission. Here, the app may have been run many times, for months, before we all of a sudden need to request another permission.

在这种情况下,我们应该跟踪我们是否自己请求许可?还是Android M API中缺少我告诉我们是否曾经问过的内容?

In those cases, are we supposed to track whether or not we asked for the permission ourselves? Or is there something in the Android M API that I am missing that tells us whether we asked before or not?

推荐答案

根据当前示例:在SharedPreferences中存储一个布尔值,并使用key作为您的权限代码和值(如上所述),以指示该偏好设置之前是否已被拒绝.

Store a boolean in SharedPreferences with key as your permission code and value as indicated above, to indicate whether that preference has been denied before.

遗憾的是,您可能无法在应用程序运行时对照已接受但后来被拒绝的首选项进行检查.最终规格不可用,但是您的应用可能会重新启动或获得模拟值,直到下一次启动.

Sadly, you probably can't check against a preference that has been accepted and later denied while your app is running. The final spec is not available, but there's a chance that your app either gets restarted or gets mock values until the next launch.

这篇关于在Android M的运行时权限中,我们如何区分永不停止和永不停止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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