Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check for Mock Location in Android Marshmallow?

How to detect if the location is triggered with Mock Location in Android Marshmallow?

Previously, I used Settings.Secure.ALLOW_MOCK_LOCATION

But, in API level 23, this has been deprecated.

I want to check if the trigger is with Fake location or original GPS ?

Now, what is the alternative to check if Mock Location is enabled or not Android Marshmallow?

like image 648
Bharath Avatar asked Sep 19 '15 12:09

Bharath


People also ask

How do I turn on mock mock location on Android?

Open the 'Developer Options' menu and scroll to the bottom until you find 'Debugging'. Activate Mock Location by going to the 'Allow Mock Locations' option.

Where is the Select mock location app?

First, go to “Settings” → navigate to “About Device” → and finally tap multiple times on “Build number” at the bottom of the menu to activate the Developer Mode. In this “Developer Options” menu, scroll down to “Debugging”, and tap on “Select mock location app”.

Where is mock location in xiaomi?

1 Go to Settings and then click on My device > All specs. 2 Navigate to MIUI version and tap on it 7 to 10 times repeatedly. 3 Then head to Additional settings and click Developer options. 4 In the Select mock location app section, select the downloaded mock location app.


1 Answers

If you are using FusedLocationProviderApi and have set mock location using setMockLocation(mGoogleApiClient, fakeLocation); in the callback/pendingIntentCallback the returned Location object contains KEY_MOCK_LOCATION extra, a boolean that indicates that received object is mock.

@Override

public void onLocationChanged (Location location){    
   Bundle extras = location.getExtras();
   boolean isMockLocation = extras != null && extras.getBoolean(FusedLocationProviderApi.KEY_MOCK_LOCATION, false);

}
like image 67
Nikola Despotoski Avatar answered Sep 18 '22 20:09

Nikola Despotoski