I am trying to enable GPS settings using dialog box with the user confirmation.
here is the code
public void turnGPSOn() {
LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
boolean enabled = service
.isProviderEnabled(LocationManager.GPS_PROVIDER);
if (!enabled) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
this);
alertDialogBuilder
.setMessage("GPS is disabled in your device. Enable it?")
.setCancelable(false)
.setPositiveButton("Enable GPS",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
/** Here it's leading to GPS setting options*/
Intent callGPSSettingIntent = new Intent(
android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(callGPSSettingIntent);
}
});
alertDialogBuilder.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = alertDialogBuilder.create();
alert.show();
}
}
Above code will lead the user to gps setting options.But i have seen in many apps(recent apps) where after confirmation gps setting will be enabled to High-Accuracy automatically.
My Question is i need to enable GPS setting to Battery Saving mode(or any other) after user confirmation(Dialog 'yes') without going to GPS settings.
MinSDK:9
TargetSDK:23
BuildToolVer:23.0.1
Regards.