Gps - Change Location Mode to High Accuracy Programmatically Android

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

Is it possible to get the information on the location mode which the user has selected among the three modes under the location settings options i.e

1.Hight Accuracy

2.Battery Saving

3.GPS Only

I want to programmatically check if user has selected High Accuracy mode if not then enable it automatically. Is it possible ? Please advice.

Answers

It is possible to get the device s current location mode since API level 19 (Kitkat)  :

public int getLocationMode(Context context)
{
return Settings.Secure.getInt(activityUnderTest.getContentResolver(), Settings.Secure.LOCATION_MODE);

}

http://developer.android.com/reference/android/provider/Settings.Secure.html#LOCATION_MODE http://developer.android.com/reference/android/provider/Settings.Secure.html#LOCATION_MODE

  0 = LOCATION_MODE_OFF

1 = LOCATION_MODE_SENSORS_ONLY
2 = LOCATION_MODE_BATTERY_SAVING
3 = LOCATION_MODE_HIGH_ACCURACY

So you want something like

if(getLocationMode(context) == 3)
{
// do stuff
}

Unfortunately you can t set the location mode programmatically but you can send the user directly to the settings screen where he can do that:

startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/25175517/change-location-mode-to-high-accuracy-programmatically-android

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils