Android 11 后台位置权限“仅在使用应用时允许"不授予许可 [英] Android 11 background location permission "Allow only while using the app" does not grant permission
问题描述
正如标题所说,我目前正在将我的应用更新到 SDK 30,但在使用 ACCESS_BACKGROUND_LOCATION
权限时遇到了问题.请求权限后,用户将进入应用位置权限设置,并提供 4 个选项:
As the title says, I'm currently in the process of updating my app to SDK 30 and having trouble with the ACCESS_BACKGROUND_LOCATION
permission. Upon requesting the permission, the user is taken to the app location permission settings and is given 4 options:
- 一直允许
- 仅在使用应用程序时允许
- 每次都问
- 拒绝
除始终允许"之外的所有选项不授予权限并在 onRequestPermissionsResult()
回调函数内的 grantResults
IntArray
中返回一个 -1
.为什么?这是令人难以置信的混乱.命名会让人相信权限会被授予,并且只有当应用程序处于焦点时才会发出后台权限请求.是否可以删除仅在使用应用程序时允许"?选项中的选项?我怎样才能解决这个问题??我只看到这些选项让用户感到困惑,因为不会授予权限除非他们选择始终允许".
All choices except "Allow all the time" do not grant the permission and return a -1
in the grantResults
IntArray
inside the onRequestPermissionsResult()
callback function. Why? This is incredibly confusing. The naming would lead one to believe the permission would be granted and background permission requests only be made when the app is in focus. Is it possible to remove the "Allow only while using the app" option from the choices? How can I fix this?? I only see these choices confusing the user since the permission won't be granted unless they choose "Allow all the time".
推荐答案
后台位置权限与其他权限不同.这是将位置权限从仅前台提升到前台的请求背景.
Background location permission does not work like other permissions. It's a request to elevate location permission from foreground-only to foreground & background.
用户必须有意识地选择始终允许";为了做到这一点并授予后台位置权限.否则,该权限将被视为被拒绝.
User has to consciously select "Allow all the time" in order to do that and grant background location permission. Otherwise that permission is considered denied.
除非已经授予前台位置,否则您甚至无法请求后台位置 - 当系统权限活动出现时,它应该已经选择了选项 2 或 3.
You cannot even request background location unless foreground location is already granted - when system permission activity shows up it should already have option 2 or 3 selected.
参见 https://developer.android.com/training/位置/权限#request-background-location
这篇关于Android 11 后台位置权限“仅在使用应用时允许"不授予许可的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!