Mar 3, 2011

How to check if GPS is currently enabled or disabled

Using the method Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED), we can get the allowed location provider, GPS. To check if GPS is currently enabled or disabled, using the code:

        String GpsProvider = Settings.Secure.getString(getContentResolver(),
Settings.Secure.LOCATION_PROVIDERS_ALLOWED);

if(GpsProvider.equals("")){
//GPS Disabled
gpsState.setText("GPS Disable");
}else{
//GPS Enabled
gpsState.setText("GPS Enable");
}



Related:
- Start Location setting if GPS disabled
- Detect GPS ON/OFF status using android.provider.Settings.Secure

1 comment:

  1. String GpsProvider = Settings.Secure.getString(getContentResolver(),
    Settings.Secure.LOCATION_PROVIDERS_ALLOWED);

    if (GpsProvider.toLowerCase().indexOf("gps") >= 0 ) {
    return true;
    } else {
    return false;
    }

    ReplyDelete

Infolinks In Text Ads