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?
Asked
Active
Viewed 509 times
4
-
Did you find a solution for this? – Maryam Mirzaie Jan 28 '20 at 10:41
-
@MJane take a look at my answer – Selphiron Jan 29 '20 at 10:18
3 Answers
2
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();

Selphiron
- 897
- 1
- 12
- 30
0
It is impossible without Google Play Services. You can just open location settings page without it. So user can enable it manually.

Samir Alakbarov
- 1,120
- 11
- 21