简体   繁体   English

FusedLocationProviderApi:LocationRequest.setPriority如何与“位置模式”设备设置一起使用?

[英]FusedLocationProviderApi: how does LocationRequest.setPriority work with “Location mode” device setting?

Two questions: 两个问题:

  1. How does setting LocationRequest.setPriority(priority) work with the "Location mode" device setting? 设置LocationRequest.setPriority(priority)如何与“位置模式”设备设置一起使用?

    If application calls LocationRequest.setPriority(PRIORITY_HIGH_ACCURACY) is called and device setting is set to "Battery saving", I assume the application won't be able to use GPS? 如果应用程序调用LocationRequest.setPriority(PRIORITY_HIGH_ACCURACY)并将设备设置设置为“省电”,我认为该应用程序将无法使用GPS?

在此处输入图片说明

  1. Another question is, with FusedLocationApi how can I check if the device setting is set to High Accuracy? 另一个问题是,如何使用FusedLocationApi检查设备设置是否设置为“高精度”?
  1. Yes, you are right that device settings has more preference than what you are asking for. 是的,您很对,设备设置比您的要求更具偏好。 Hence, if device settings is set to "Battery Saver", application won't be able to use GPS. 因此,如果设备设置设置为“省电模式”,则应用程序将无法使用GPS。

  2. You don't need FusedLocationProvider to check for location setting in device. 您不需要FusedLocationProvider来检查设备中的位置设置。 Use below code:- 使用以下代码:-

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

Check locationMode for possible return values. 检查locationMode以获取可能的返回值。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM