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.
Asked
Active
Viewed 1,881 times
2 Answers
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
-
1Thank you this is exactly what I needed – materoy Jun 27 '20 at 16:35
-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