Check if 'Allow dummy locations' is enabled

Asked

Viewed 2,975 times

5

I have an app that needs the "Allow Dummy Locations" option of the standard Gallery app enabled to work. How to check if it is enabled? How to send the user to this item of my case is disabled? This option is in the Programmer menu, it is a hidden menu... How to activate this menu and send the person to it?

2 answers

7


I resolved...

To check if the option is enabled:

private boolean isMockSettingsON() {
        return !Settings.Secure.getString(getContentResolver(),
                Settings.Secure.ALLOW_MOCK_LOCATION).equals("0");
}

To send the user to the dev menu:

Intent intent = new Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS);
startActivity(intent);

1

Complementing the answer, the object Location has a property informs if it was generated by mock, isFromMockProvider.

This is available from API 18.

Example:

if(!location.isFromMockProvider()){
 // Esta localização não foi gerada por um simulador
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.