我的应用程序面向 API 28。我有一个发送位置更新的前台服务。
当满足以下条件时,应用程序将停止发送位置:
- 在 Android 10 上运行
- 应用程序在后台运行
- 位置权限被选择为“仅在使用应用程序时允许”
运行时
adb shell dumpsys package packageName
我看到了
android.permission.ACCESS_BACKGROUND_LOCATION: granted=false
从文档来看,“android.permission.ACCESS_BACKGROUND_LOCATION”权限似乎是向后兼容的。
如何解决这个问题?有没有办法禁用三态权限请求?
最佳答案
每https://developer.android.com/about/versions/10/privacy/changes#app-access-device-location
An app is considered to be accessing location in the background unless one of the following conditions is satisfied:
- An activity belonging to the app is visible.
- The app is running a foreground service that has declared a foreground service type of location.
您正在使用前台服务来获取位置更新,但(我假设)您没有告诉操作系统,因此它认为您正在后台访问该位置。您需要做的就是声明您的前台服务进程位置。
<service android:name="com.example.MyForegroundService"
android:foregroundServiceType="location"/>
现在,当您的服务运行时,操作系统会将您的应用视为位于前台,以便审核位置访问 - 并且您不需要 ACCESS_BACKGROUND_LOCATION
。
关于android - 应用程序未从 Android 10 上的前台服务发送位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61643442/