Mar 4, 2011

Start Location setting if GPS disabled

The following code can be used to start Location setting:

Intent intent = new Intent(Settings.ACTION_SECURITY_SETTINGS);
startActivity(intent);


This example will start Location setting if GPS is curently disabled:
        String GpsProvider = Settings.Secure.getString(getContentResolver(),
Settings.Secure.LOCATION_PROVIDERS_ALLOWED);

if(GpsProvider.equals("")){
//GPS Disabled
gpsState.setText("GPS Disable");
Intent intent = new Intent(Settings.ACTION_SECURITY_SETTINGS);
startActivity(intent);
}else{
//GPS Enabled
gpsState.setText("GPS Enable");
}


Related:
- How to check if GPS is currently enabled or disabled
- Detect GPS ON/OFF status using android.provider.Settings.Secure
- Settings.ACTION_LOCATION_SOURCE_SETTINGS vs. Settings.ACTION_SECURITY_SETTINGS

2 comments:

  1. FYI, it is better to use Settings.ACTION_LOCATION_SOURCE_SETTINGS instead of Settings.ACTION_SECURITY_SETTINGS.
    the reason is that some phones (such as my HTC Desire) have moved the GPS settings out of the Security page. Using the suggested intent gets the user to the GPS settings wherever they are.

    ReplyDelete

Infolinks In Text Ads