Check that Simulated Locations are active

Asked

Viewed 54 times

2

I’m developing an app that will use GPS to record a route.

There are applications ( an example ) , which simulate its location.

This is done through a development option :

inserir a descrição da imagem aqui

I wonder if it is possible to know if this option is active?

So that positive case does not allow the user to start the route.

1 answer

2


From API18 to class Location provides the method isFromMockProvider() returning true if the location originates from the mock Provider.

To know if simulated locations are active use preview Provider.settings.Secure

public static boolean isMockLocationsOn(Context context) {
  // returna true se as localizações simuladas estão activas.
  if (Settings.Secure.getString(context.getContentResolver(),
                                Settings.Secure.ALLOW_MOCK_LOCATION).equals("0"))
     return false;
  else
     return true;
 }

Code adapted from Soen.

Note that ALLOW_MOCK_LOCATION is now considered obsolete as of API23.

Browser other questions tagged

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