1
votes

Using the old Android location manager, you can detect whether location is enabled for GPS (and similarly for network location) using:

LocationManager x = (LocationManager) getSystemService(Activity.LOCATION_SERVICE);
boolean isGPSEnabled = x.isProviderEnabled(LocationManager.GPS_PROVIDER);

Is there a new way of doing this with the Google Play services location APIs? The documentation suggests

If you are currently using the Android framework location APIs, you are strongly encouraged to switch to the Google Play services location APIs as soon as possible.

https://developer.android.com/training/location/index.html https://developer.android.com/reference/com/google/android/gms/location/package-summary.html

1
Take that encouragement with a large pinch of salt. There's quite a few apps that get no benefit from the new APIs, and the old ones aren't going away (the new one is built on top of them). The new ones also won't work on a custom ROM or any phone which hasn't paid google for the right to use them, unless the owner pirated Google Play Services. - Gabe Sechan

1 Answers

1
votes

As Gabe commented, I think you don't have to move to new APIs (FusedLocationProviderApi) if your use case is satisfied with LocationManager. Huge downside of using FuedLocationProviderApi is that, it doesn't seem working well if you only enable network location provider.

Having said that, for original questions, if you decide to use FusedLocationProviderApi, you can use SettingsApi to confirm current user's settings for specific LocationRequest. SettingsApi also provide a means to recover from insufficient settings, i.e., it can show dialog to "enable location access" and you don't have to redirect user to settings page.