Android 12 Access_fine_location即使被授予了允许

发布于 2025-02-12 03:59:14 字数 543 浏览 0 评论 0原文

在Android 12设备(API 31)上,

用户授予了精确和近似权限,并且应用程序正常工作。
当用户通过进入设置关闭设备位置时,我会看到Access_Fine_Location许可未授予。
当通过导航到设置进行检查时,我们会看到精确的位置已打开,并设置了位置以允许所有时间。仍然返回Access_Fine_Location未授予。
在此情况下,下面的代码返回false-

override fun hasLocationPermission(): Boolean {
    return PermissionChecker.checkSelfPermission(
        mContext,
        android.Manifest.permission.ACCESS_FINE_LOCATION
    ) === PermissionChecker.PERMISSION_GRANTED
}

因此,如果用户关闭设备位置,则未授予“前景位置”权限。这是Android 12中的预期行为吗?
请协助。

On Android 12 devices (API 31),

User has GRANTED both the precise and approximate permissions and app is working fine post that.
When user turns off the device location by going into settings, I see the ACCESS_FINE_LOCATION permission as NOT GRANTED.
When checked by navigating into settings, we see precise location is turned on and location is set to allow all the time. Still the ACCESS_FINE_LOCATION is returned as NOT GRANTED.
In this scenario below code returns false -

override fun hasLocationPermission(): Boolean {
    return PermissionChecker.checkSelfPermission(
        mContext,
        android.Manifest.permission.ACCESS_FINE_LOCATION
    ) === PermissionChecker.PERMISSION_GRANTED
}

So if user turns off device location then FORGROUND LOCATION PERMISSION IS NOT GRANTED. is this the expected behaviour in Android 12?

Please assist.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

末が日狂欢 2025-02-19 03:59:14

我认为许可证返回许可证_denied_app_op。 GERMISENDCHECKER可以返回三个结果:cermission_denied,cermission_granted或cermission_denied_app_op_op。如果要结果cermission_granted,请尝试使用ContextCompat。

override fun hasLocationPermission(): Boolean {
return ContextCompat.checkSelfPermission(
    mContext,
    android.Manifest.permission.ACCESS_FINE_LOCATION
) == PackageManager.PERMISSION_GRANTED }

I think that PermissionChecker returns PERMISSION_DENIED_APP_OP. PermissionChecker can return three result: PERMISSION_DENIED, PERMISSION_GRANTED or PERMISSION_DENIED_APP_OP. If you want result PERMISSION_GRANTED, try to use ContextCompat.

override fun hasLocationPermission(): Boolean {
return ContextCompat.checkSelfPermission(
    mContext,
    android.Manifest.permission.ACCESS_FINE_LOCATION
) == PackageManager.PERMISSION_GRANTED }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文