Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ask user to enable GPS location in android without GoogleAPI or Google Play Services

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?

like image 325
Selphiron Avatar asked Sep 18 '25 21:09

Selphiron


1 Answers

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();
like image 135
Selphiron Avatar answered Sep 21 '25 12:09

Selphiron