Reputation: 23
I would like to programmatically determine whether the user has agreed or disagreed to the "Location Consent" dialog that appears when you turn your on your GPS on Android devices.
I have not been able to find where to get this information from, and I'm not sure whether it is actually available anywhere within the code?
Thanks!
Upvotes: 2
Views: 1135
Reputation: 3939
Check the newer gms.location.SettingsApi. You build a LocationRequest and ask if the current system settings are compatible, and handle the result as needed.
https://developer.android.com/reference/com/google/android/gms/location/SettingsApi.html
Upvotes: 0
Reputation: 201
This is about location mode. if the user agreed to the "Location Consent", location mode set on High Accuracy.
For check this mode you can use following code:
public static boolean checkLocationSettings(Context context) {
int locationMode = 0;
String locationProviders;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){
try {
locationMode = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE);
} catch (SettingNotFoundException e) {
e.printStackTrace();
}
return (locationMode != Settings.Secure.LOCATION_MODE_OFF && locationMode == Settings.Secure.LOCATION_MODE_HIGH_ACCURACY); //check location mode
}else{
locationProviders = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
return !TextUtils.isEmpty(locationProviders);
}
}
Upvotes: 1