shouldShowRequestPermissionRationale为假

编程入门 行业动态 更新时间:2024-10-28 10:34:02
本文介绍了shouldShowRequestPermissionRationale为假的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我向我的应用添加了位置权限.现在安装应用程序时,它会询问用户权限.这是我的代码:

I added location permissions to my app. When installing the app now it asks the user for permission. This is my code:

if (fragment.shouldShowRequestPermissionRationale(Manifest.permission.ACCESS_FINE_LOCATION) { fragment.requestPermissions(....); }

但是,当我安装了以前的应用程序版本时,我没有此位置权限并更新了该应用程序,则它不要求获得权限,例如

But when I have my previous app verison installed, where I didn't have this location permission and update the app then it does not ask for permission, as

fragment.shouldShowRequestPermissionRationale(Manifest.permission.ACCESS_FINE_LOCATION

返回 false

通常,仅当用户单击不再询问"时,这才应返回false.我在这里想念什么?

Normally this should only return false when the user clicked "never ask again". What am I missing here?

推荐答案

shouldShowRequestPermissionRationale()也会返回false.这就是为什么理想的情况下,您首先要请求权限,然后通过 onRequestPermissionsResult 检查权限结果对象是什么,并在随后的所有请求之后检查 shouldShowRequestPermissionRationale()以查看是否用户已选中不再询问"选项.

shouldShowRequestPermissionRationale() also returns false if the user has never been asked for permission before. That's why ideally you first ask for permission, you then check what the permission result object is through onRequestPermissionsResult, and follow any consequent request with the check for shouldShowRequestPermissionRationale() to see whether the user has checked the never ask again option.

编辑-检查此答案中的示例: stackoverflow/a/34612503/10300673

EDIT- Check the example in this answer: stackoverflow/a/34612503/10300673

更多推荐

shouldShowRequestPermissionRationale为假

本文发布于:2023-10-16 11:20:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1497409.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:shouldShowRequestPermissionRationale

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!