FusedLocationProvider Api:LocationRequest.setPriority 如何与 "Location mode" 设备设置一起使用?

FusedLocationProviderApi: how does LocationRequest.setPriority work with "Location mode" device setting?

两个问题:

  1. 设置 LocationRequest.setPriority(priority) 如何与“定位模式”设备设置一起使用?

    如果应用程序调用 LocationRequest.setPriority(PRIORITY_HIGH_ACCURACY) 被调用并且设备设置设置为“省电”,我认为该应用程序将无法使用 GPS?

  1. 另一个问题是,对于 FusedLocationApi,我如何检查设备设置是否设置为高精度?
  1. 是的,你是对的,设备设置比你要求的更偏好。因此,如果设备设置设为 "Battery Saver",应用程序将无法使用 GPS。

  2. 您不需要 FusedLocationProvider 来检查设备中的位置设置。使用以下代码:-

    int locationMode = 
    Settings.Secure.getInt(activityUnderTest.getContentResolver(), 
    Settings.Secure.LOCATION_MODE);
    

检查 locationMode 可能的 return 值。

if(locationMode == LOCATION_MODE_HIGH_ACCURACY) {
   //request location updates
} else { //redirect user to settings page
   startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
}