1) 请求后台和前台位置。
String [] permission = {Manifest.permission.ACCESS_BACKGROUND_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION};
requestPermissions(permission,100);
2)清单
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"></uses-permission>
3) On release build onRequestPermissionsResult shows not granted when "Allow all the time" is selected with below error.
2019-07-31 16:15:27.329 1293-1311/? E/PackageManager: Cannot grant restricted non-exempt permission android.permission.ACCESS_BACKGROUND_LOCATION for package xyz.abc.com
2019-07-31 16:49:38.412 11858-11858/? D/MainActivity: permission: android.permission.ACCESS_BACKGROUND_LOCATION
2019-07-31 16:49:38.412 11858-11858/? D/MainActivity: permission: android.permission.ACCESS_COARSE_LOCATION
2019-07-31 16:49:38.412 11858-11858/? D/MainActivity: grantResults: -1
2019-07-31 16:49:38.412 11858-11858/? D/MainActivity: grantResults: 0
注意: 设备:Pixel 3a XL
适用于调试构建,但在发布构建中失败。
设备:Pixel 3 XL。适用于调试和发布版本。