Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Settings.Secure.ALLOW_MOCK_LOCATION always returns 1 even mock setting is Off

I'm developing an app where a user will not be able to use it if mock location setting is enabled using this piece of code

if (Settings.Secure.getString(context.getContentResolver(),
            Settings.Secure.ALLOW_MOCK_LOCATION).equals("0"))
        return false;
    else
        return true;

well it was working fine in most of my test devices from KitKat to Marshmallow systems, until I tried my app on this single device with Marshmallow OS, the mock setting is clearly OFF, but that code above keeps telling me that the mock setting is ON, is this a bug? or am i missing something here?

like image 307
Jeff Avatar asked Jan 07 '23 03:01

Jeff


1 Answers

Checking out this answer from here.

boolean isMock = false;
if (android.os.Build.VERSION.SDK_INT >= 18) {
    isMock = location.isFromMockProvider();
} else {
    isMock = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION).equals("0");
}

This might help you

like image 86
Nongthonbam Tonthoi Avatar answered Mar 13 '23 02:03

Nongthonbam Tonthoi