Check if simulated Locations are active

2

I'm developing an application that will use GPS to log a route.

There are apps ( an example ) that simulate your location.

This is done through a development option:

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

In this case, do not allow the user to start the route.

    
asked by anonymous 03.03.2016 / 21:38

1 answer

2

From the API18 class Location provides the < a href="http://developer.android.com/intl/en/reference/android/location/Location.html#isFromMockProvider%28%29"> isFromMockProvider () which returns true se the location originates from the mock provider .

To find out if simulated locations are active, use provider 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;
 }

Adapted SOen code

Note that ALLOW_MOCK_LOCATION is now considered obsolete from the API23.

    
03.03.2016 / 22:38