ACCESS_BACKGROUND_LOCATION不适用于低于Q(29)的Android版本 [英] ACCESS_BACKGROUND_LOCATION Not Working on Lower Than Q (29) Android Versions

查看:107
本文介绍了ACCESS_BACKGROUND_LOCATION不适用于低于Q(29)的Android版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序针对Android API28.

My app is targeting Android API 28.

根据文档,我应该要求在Android API上运行时, ACCESS_BACKGROUND_LOCATION 以及 ACCESS_FINE_LOCATION 29 .

According to the documentation, I should be requesting ACCESS_BACKGROUND_LOCATION, along with ACCESS_FINE_LOCATION when running on Android API < 29.

我已经尝试过这样做,但是在 onRequestPermissionResults()中,从未授予 ACCESS_BACKGROUND_LOCATION 并返回 PackageManager.PERMISSION_DENIED .我的印象是,当请求<上的另一个前台许可时,将隐式授予该权限. 29 .

I have tried doing this but in onRequestPermissionResults(), ACCESS_BACKGROUND_LOCATION is never granted and returns PackageManager.PERMISSION_DENIED. I was under the impression this would be implicitly granted when requesting another foreground permission on < 29.

或者,我可以从API<上的请求中删除权限. 29 ,一切似乎都按预期进行,但我意识到我会违背文档.

Alternatively, I can remove the permission from the request on API < 29 and everything seems to work as expected but I am conscious that I would be going against the documentation.

问题

我可以在Android版本<上省略对 ACCESS_BACKGROUND_LOCATION 的明确请求.29,并且仍能按预期工作,同时符合API 29 中的文档有效吗?

Can I omit an explicit request for the ACCESS_BACKGROUND_LOCATION on Android versions < 29 and still work as expected whilst conforming to documentation in API 29 which works?

推荐答案

文档指出:

如果您的应用定位到Android 10(API级别29)或更低版本,请完成请按照以下步骤请求ACCESS_BACKGROUND_LOCATION:

If your app targets Android 10 (API level 29) or lower, complete the following steps to request ACCESS_BACKGROUND_LOCATION:

1)包括ACCESS_BACKGROUND_LOCATION权限,以及您的ACCESS_COARSE_LOCATION或ACCESS_FINE_LOCATION权限应用程序的清单.

1) Include the ACCESS_BACKGROUND_LOCATION permission, as well as either the ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission, in your app's manifest.

2)请求ACCESS_BACKGROUND_LOCATION权限,以及以下之一其他位置权限:ACCESS_COARSE_LOCATION或ACCESS_FINE_LOCATION.您可以一次申请这些权限操作.

2) Request the ACCESS_BACKGROUND_LOCATION permission, as well as one of the other location permissions: ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION. You can request these permissions in a single operation.

这些说明有点模棱两可,因为它们没有描述每个API版本所期望的行为.ACCESS_BACKGROUND_LOCATION是在API 29中添加的,因此在API 28及更低版本中不存在,因此在这些情况下,由于这些版本的Android上的代码中不存在该权限,因此它基本上是无操作的.

The instructions are a bit ambiguous, because they don't describe what behavior to expect on each API version. The ACCESS_BACKGROUND_LOCATION was added in API 29, so it doesn't exist in API 28 and lower, so in those cases it's basically a no-op since the permission doesn't exist in the code on those versions of Android.

因此,对 ACCESS_BACKGROUND_LOCATION 的权限请求将向用户显示API 29及更高版本的其他选项,即使您的目标是较低的API版本,以及在较旧的API上运行代码时Android版本的请求 ACCESS_BACKGROUND_LOCATION 的请求将被自动拒绝.不过,一切都很好,因为对于那些旧版本的Android而言,该权限根本不存在.

As a result, the permission request for ACCESS_BACKGROUND_LOCATION will show the extra options to the user on API 29 and higher, even if you are targeting a lower API version, and when running the code on older versions of Android the request for ACCESS_BACKGROUND_LOCATION will be automatically denied. All is well though, since that permission doesn't exist for those older versions of Android anyway.

在您的应用程序代码中,如果对API 28或更低版本的 ACCESS_BACKGROUND_LOCATION 权限被拒绝,则请忽略该权限拒绝,因为在那些Android版本上是期望的.另外,您可以忽略对API 28或更低版本的 ACCESS_BACKGROUND_LOCATION 的请求,以达到相同的结果.

In your app code, if the ACCESS_BACKGROUND_LOCATION permission is denied on API 28 or lower, just ignore the permission denial, since it is expected on those Android versions. Alternatively, you can just omit the request to ACCESS_BACKGROUND_LOCATION on API 28 or lower to achieve the same result.

这篇关于ACCESS_BACKGROUND_LOCATION不适用于低于Q(29)的Android版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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