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
FYI, it is better to use Settings.ACTION_LOCATION_SOURCE_SETTINGS instead of Settings.ACTION_SECURITY_SETTINGS.
ReplyDeletethe 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.
Thx Brain, :)
ReplyDelete