1

How can I check if the GPS feature is enabled on a device, so that I can update a map widget. I've already done the location permission handler feature part.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
materoy
  • 370
  • 1
  • 3
  • 10

2 Answers2

1

I am having issues duplicating this question.

As per this link, the best way is

 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();
}
rafon
  • 1,469
  • 11
  • 21
-2

add geolocator package to your project , then you can check if location is enabled or not with :

  final Geolocator _geolocator = Geolocator();
  ...
  ...
 bool enabled = await _geolocator.isLocationServiceEnabled();
Nickan
  • 466
  • 5
  • 17