I'm developing an app on Android OS. I don't know how to check if Location Services are enabled or not.
I need a method that returns "true" if they are enabled and "false" if not (so in the last case I can show a dialog to enable them).
I'm developing an app on Android OS. I don't know how to check if Location Services are enabled or not.
I need a method that returns "true" if they are enabled and "false" if not (so in the last case I can show a dialog to enable them).
As Peter McClennan indicated, Google has an API that works extremely well with the new fused location provider. A completely worked example is at Google Sample Code at Github You don't need to code a user dialog to ask them to change settings as it is done automatically with the API.
Working off the answer above, in API 23 you need to add "dangerous" permissions checks as well as checking the system's itself:
To check for network provider you just need to change the string passed to isProviderEnabled to LocationManager.NETWORK_PROVIDER if you check the return values for both GPS provider and NETwork provider - both false means no location services
I use such way for NETWORK_PROVIDER but you can add and for GPS.
In onCreate I put
And method of checking
You can request the location updates and show the dialog together, like GoogleMaps doas also. Here is the code:
If you need more info check the LocationRequest class.