1

I have this scenario : My android service location is enabled but my gps (gps symbol) is not enabled.

service location

gps

I want to check if my service location is enabled or not and launch activity. I want to check if my gps (see gps print screen - gps symbol) is enabled or not and toast message to user.

The code below checks if my gps (see gps print screen - gps symbol) is enabled or not only but does not check if service location is enabled. <== this is what I need to... thx

final LocationManager locationManager =
            (LocationManager) context.getSystemService(context.LOCATION_SERVICE);

    try {
        gps_enabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);

I need to identify both situations and handle this...

Lets suppose I have my gps (background) disabled. (see gps print screen - gps symbol) and I have my service location enabled.

Al2x
  • 871
  • 5
  • 22
  • 35
  • possible duplicate of http://stackoverflow.com/questions/843675/how-do-i-find-out-if-the-gps-of-an-android-device-is-enabled/7990939#7990939 – cafebabe1991 Oct 05 '15 at 14:44
  • thats the deal. I checked gps disabled with the locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER how can I know if my service location is enabled or not ... – Al2x Oct 05 '15 at 14:49
  • Looks like you have only the network provider enabled. You can check that too using the same way you check the GPS provider. – Daniel Nugent Oct 05 '15 at 14:58
  • nop. In this situation as you can see in print screen I have service location enabled and gps (gps_provider) disabled. – Al2x Oct 05 '15 at 15:25
  • 1
    After @drschultz reply I got what you told in comment thx. – Al2x Oct 05 '15 at 16:42

1 Answers1

1

If you are using LocationManager to determine which location services are available, you'll be able to tell if location services are turned on or off. For instance, with the following code:

LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
boolean isGpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
boolean isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

Log.d("LOCATION SERVICES", "isGpsEnabled="+isGpsEnabled+" isNetworkEnabled="+isNetworkEnabled);

If the device Location Services are turned off, both isGpsEnabled and isNetworkEnabled will be false. If just GPS is turned off, but location services are turned on, isGpsEnabled would be false, but isNetworkEnabled would be true. If the device has location services turned on, including GPS, then both will be true.

NoChinDeluxe
  • 3,328
  • 1
  • 13
  • 28