Search code examples
androidandroid-fusedlocation

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?

    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?

enter image description here

  1. Another question is, with FusedLocationApi how can I check if the device setting is set to High Accuracy?

Solution

    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.

    2. You don't need FusedLocationProvider to check for location setting in device. Use below code:-

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

    Check locationMode for possible return values.

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