【问题标题】:FusedLocationProviderApi: how does LocationRequest.setPriority work with "Location mode" device setting?FusedLocationProviderApi:LocationRequest.setPriority 如何与“位置模式”设备设置一起使用?
【发布时间】:2017-12-25 17:09:30
【问题描述】:
两个问题:
-
LocationRequest.setPriority(priority) 设置如何与“位置模式”设备设置一起使用?
如果应用程序调用LocationRequest.setPriority(PRIORITY_HIGH_ACCURACY) 并且设备设置设置为“省电”,我假设应用程序将无法使用 GPS?
- 另一个问题是,使用 FusedLocationApi 如何检查设备设置是否设置为高精度?
【问题讨论】:
标签:
android
android-fusedlocation
【解决方案1】:
是的,您说得对,设备设置的偏好比您要求的要多。因此,如果设备设置为“省电模式”,应用程序将无法使用 GPS。
-
您不需要 FusedLocationProvider 来检查设备中的位置设置。使用以下代码:-
int locationMode =
Settings.Secure.getInt(activityUnderTest.getContentResolver(),
Settings.Secure.LOCATION_MODE);
检查 locationMode 以获取可能的返回值。
if(locationMode == LOCATION_MODE_HIGH_ACCURACY) {
//request location updates
} else { //redirect user to settings page
startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
}