When the GPS location of a device is disabled, I want to show a message to the user, where he can press "OK" to enable it or "Cancel" to leave it as it is. I found a lot of examples but all of them either use the GoogleAPI or Google Play Services. Is there another way?
As stated in answers to similar questions, this is not quite possible.
I use locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
to check whether the GPS location service is enabled.
If not, I prompt the user to enable it and direct them to the gps location settings of android. They can hit back to return to the app:
new AlertDialog.Builder(MainActivity.this)
.setMessage("GPS Location is disabled")
.setPositiveButton("ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface paramDialogInterface, int paramInt) {
MainActivity.this.startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
}
})
.setNegativeButton("Cancel", null)
.show();
Toast.makeText(MainActivity.this, "Canceled",Toast.LENGTH_LONG).show();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With