-1

I am developing an application in which the user's location is tracked using the GPS provider only (device only mode of Location) . Therefore if the user sets his location priority to Approximate Location using Wifi and Data, the application wont work as intended. Therefore I need to check out the user selection of location mode (High accuracy, Approximate Location or Device only) programmatically and display appropriate dialog boxes. What would be a clean way to achieve this?

Sourav Kanta
  • 2,727
  • 1
  • 18
  • 29
  • Take a look at the answer here: http://stackoverflow.com/questions/30467850/monitoring-geofences-after-user-turns-location-service-off-and-on/30580898 – Daniel Nugent Jun 10 '16 at 14:42
  • @DanielNugent I don't want as heavy weight a thing as Broadcast Receiver. i feel Karen's answer is the way to go. Let me check. – Sourav Kanta Jun 10 '16 at 15:06
  • That linked answer has the code you need in it, but a lot of other stuff too. I just posted an answer here that has only the code you need.... – Daniel Nugent Jun 10 '16 at 16:07

3 Answers3

1

You can LocationProvider.getAccuracy: https://developer.android.com/reference/android/location/LocationProvider.html

From the docs: int getAccuracy () Returns a constant describing horizontal accuracy of this provider. If the provider returns finer grain or exact location, ACCURACY_FINE is returned, otherwise if the location is only approximate then ACCURACY_COARSE is returned.

Karen Forde
  • 1,117
  • 8
  • 20
0

1, To check the provider mode (gps, network, cellar-id)

LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
//get currently used providers
locationManager.getProviders(true);

2, show dialog

new AlertDialog.Builder(this).
setTitle("Title").
setMessage("content").
show();
Ming Tong
  • 105
  • 1
  • 8
0

Note that your app will work for both GPS Only mode and also High Accuracy mode, since with both settings GPS is enabled.

In order to check if GPS is enabled, this will do the trick.

LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

boolean isGpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);

if (!isGpsEnabled) {
   //show your alert here
}
Daniel Nugent
  • 43,104
  • 15
  • 109
  • 137