0

The problem: MyLocationButton is enabled on Google Maps and GPS is off. When the user clicks on it, it just fails silently. This is a quite bad user interaction. I would like it to prompt the user to change GPS settings (like it actually does on google maps).

It seems i can redefine the handler for the button, but i like the waiting for user location and centering map part (and would gladly avoid rewriting it). Is there any way to catch the button failure event?

Thanks.

ClonedOne
  • 359
  • 1
  • 10
  • See [this question](http://stackoverflow.com/questions/16262946/how-to-enable-gps-in-android) – Nicolas Feb 05 '17 at 22:37
  • @NicolasMaltais Thank you. However this is not the point of the question. I know how to prompt the user for gps. What i would like is to catch the failure of MyLocationButton to send that request. – ClonedOne Feb 05 '17 at 22:47
  • Would checking if gps is enabled after that with [this method](http://stackoverflow.com/questions/843675/how-do-i-find-out-if-the-gps-of-an-android-device-is-enabled) work? – Nicolas Feb 05 '17 at 22:55

1 Answers1

-1

i think this will be solve it by checking if GPS is enabled and alert the user if it is disabled. i copied the code from this link.

final LocationManager manager = (LocationManager) getSystemService( Context.LOCATION_SERVICE );

    if ( !manager.isProviderEnabled( LocationManager.GPS_PROVIDER ) ) {
        buildAlertMessageNoGps();
    }

private void buildAlertMessageNoGps() {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("Your GPS seems to be disabled, do you want to enable it?")
           .setCancelable(false)
           .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
               public void onClick(@SuppressWarnings("unused") final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
                   startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
               }
           })
           .setNegativeButton("No", new DialogInterface.OnClickListener() {
               public void onClick(final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
                    dialog.cancel();
               }
           });
    final AlertDialog alert = builder.create();
    alert.show();
}
Community
  • 1
  • 1
Mehran Zamani
  • 817
  • 9
  • 29
  • Thanks but my problem is not how to check if GPS is active, but how to do it in response to MyLocationButton failure. For what i can understand this code does not do that, instead it just checks GPS availability once it is called in the activity lifecycle. Please correct me if i'm wrong – ClonedOne Feb 06 '17 at 13:57
  • when does MyLocationButton fail? when GPS was disabled. – Mehran Zamani Feb 06 '17 at 14:53