Prior to Marshmallow "Allow mock locations" option could be changed programmatically(requires root)
Settings.Secure.putInt(getContentResolver(),Settings.Secure.ALLOW_MOCK_LOCATION, 1);
But now this option is app specific, means you have to pick the mocker app in developer options.
Is there a way to change this settings (inserting my app to allowed list) programmatically ?
“Mock Location” is a hidden developer setting in the Android operating system that allows a device owner to set any GPS location for testing purposes. Despite the fact that this is a developer setting, anyone can use it just by clicking a couple of buttons in device settings.
Step 1: Download the Fake GPS Location app from the Google Play Store on your Android phone. Use the search bar, and it will pop up amongst the search results. Step 2: After installation, select this app as your mock location app on your phone by exploring your device settings.
App checks alone cannot detect fake GPS locations entirely. The app knows what it's being told by the operating system, and Android, as an open-source OS makes it easier for external exploits to be introduced. Adding app certificate integrity checks is highly recommended.
No there is no way to give access to set the default mock location app. The most you can do is display a notification to user upon opening the app for the first time, giving them instructions on how this is done though the settings.
Note that for the user to do this, there is no need for root access, but rather developer access. This allows you to set the default mock location app.
Even the best mock location apps out in the market don't have this implemented by default. Hope this helps :)
--EDIT--
However, thre is a way to make this easier for the user to access. You can point the user to the actual screen where the mock-location app is set using the code below:
startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS));
This points the user to the screen where the mock-location app is set.
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