Android 10(Api 29)新特性适配 – 后台应用增加定位限制

官方文档:https://developer.android.google.cn/preview/privacy/device-location

问题描述

后台应用要获取位置信息需要动态申请权限

<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>

在AndroidQ上运行:

  • targetSdkVersion<Q,没影响,申请权限时系统默认会加上后台位置权限
  • targetSdkVersion>=Q,需申请;
  • 应用变为后台应用90s后开始定位失败(Pixel Android Q)
  • ACCESS_BACKGROUND_LOCATION不能单独申请,需要和ACCESS_COARSE_LOCATION/ACCESS_FINE_LOCATION一起申请

解决方法

(1)动态申请即可

(2)启动前台服务

<!-需要设置foregroundServiceType为“location” ->
<service 
  android:name=".permission.LocationService"
  android:foregroundServiceType="location"
  />
上一篇 Android 10(Api 29)新特性适配 - 禁止后台启动Activity
下一篇 Android 10(Api 29)新特性适配 - 分区存储
目录
文章列表
1 Resource IDs cannot be used in a switch statement in Android library modules
Resource IDs cannot be used in a switch statement in Android library modules
2
Python判断字符串是否包含子字符串
Python判断字符串是否包含子字符串
3
RestTemplate中使用ParameterizedTypeReference参数化类型支持泛型
RestTemplate中使用ParameterizedTypeReference参数化类型支持泛型
4
Appium自动化测试(7)—— Desired Capabilities
Appium自动化测试(7)—— Desired Capabilities
5
ZooKeeper Web控制台ZKUI
ZooKeeper Web控制台ZKUI
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。