Reliable alternative of LOCATION_MODE for KitKat and above to get the degree of location access enabled by the user?

248 views Asked by At

What I'm trying to do:

Since LOCATION_PROVIDERS_ALLOWED was depreciated in API level 19, I am trying to use LOCATION_MODE to get the degree of location access enabled by the user for API above 19 as follows:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    int locationMode;
    try {
        locationMode = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE);

        // Check if Location services in ON and if YES then make sure its in either HIGH_ACCURACY or POWER_SAVING mode (Not in GPS_ONLY)
        switch (locationMode) {
            case Settings.Secure.LOCATION_MODE_OFF:
            //....
            break;

            case Settings.Secure.LOCATION_MODE_SENSORS_ONLY:
            //....
            break;

            //....
        }
    } catch (SettingNotFoundException e) {
        e.printStackTrace();
    }
}

Issue:

Now, for LOCATION_MODE, the docs mention

Note: do not rely on this value being present in settings.db or on ContentObserver notifications for the corresponding Uri.

By what I can understand, it means that its not reliable to use LOCATION_MODE. Then for API > 19, what else is recommended to use for knowing the extent to location access that has been allowed by user for the apps?

0

There are 0 answers