4

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?

Selphiron
  • 897
  • 1
  • 12
  • 30

3 Answers3

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
1

Without Google Play Services you cannot do in Android device.

Raj
  • 194
  • 1
  • 7
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