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
?
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.
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”.
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.
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With