I have an android app that uses location. But I noticed that if users disable the 'Access to my location' in Settings > Location access, nothing works anymore. How can I check that it's enabled? In case it's disabled, how to open those settings from my app?
Thanks
SOLVED :
String locationProviders = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if (locationProviders == null || locationProviders.equals("")) {
...
startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
}
Settings > Location > Mode > Battery Saving . This mode only uses WiFi, Bluetooth or mobile data instead of GPS to determine the user location. That's why you have to check if the network provider is enabled and locationManager. isProviderEnabled(LocationManager.
Add a TextView and a Button in the layout file. The TextView will display if the GPS is enabled or disabled upon the Button trigger.
You can find out which apps actually use location tracking and just disable it for those that you feel don't need it. Go to the Location page (by long-pressing the Location icon in your Quick Settings tray). Tap on “App permission” (or, if you're using Android 12, look for “App location permissions”).
Android offers two location permissions: ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION . The permission you choose determines the accuracy of the location returned by the API. android.
You can check it like that:
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) // Return a boolean
EDIT:
If you want to check the network provider:
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER) // Return a boolean
EDIT 2:
If you want to open the settings, you can use this intent:
Intent intent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With