Use the layout of the location without setting it in the settings

I am writing an application that uses the location offset feature in android.

What I would like to achieve is to mock my location without setting the "allow mock locations" flag in the developer settings.

I know this is possible because it works with this app: https://play.google.com/store/apps/details?id=com.lexa.fakegps&hl=en

What I tried:

Create apk, move it to / system / app, reboot
And I also tried it with permission and without ACCESS_MOCK_LOCATION permission in the manifest.

But all this leads to this exception:
RuntimeException: Failed to start Activity: SecurityException: secure configuration required ACCESS_MOCK_LOCATION

+6
source share
3 answers

I decompiled com.lexa.fakegps , which you talked about in the question, and what it does is this:

 private int setMockLocationSettings() { int value = 1; try { value = Settings.Secure.getInt(getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION); Settings.Secure.putInt(getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION, 1); } catch (Exception e) { e.printStackTrace(); } return value; } private void restoreMockLocationSettings(int restore_value) { try { Settings.Secure.putInt(getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION, restore_value); } catch (Exception e) { e.printStackTrace(); } } /* every time you mock location, you should use these code */ int value = setMockLocationSettings();//toggle ALLOW_MOCK_LOCATION on try { mLocationManager.setTestProviderLocation(LocationManager.GPS_PROVIDER, fake_location); } catch (SecurityException e) { e.printStackTrace(); } finally { restoreMockLocationSettings(value);//toggle ALLOW_MOCK_LOCATION off } 

Since the execution time of this code is very short, other applications are unlikely to detect a change to ALLOW_MOCK_LOCATION.

Also you need
1. requires root access to your device
2. Move the application to /system/app or /system/priv-app

I tried it in my project and it works great.

+13
source

To do this, you need root access to your device.

+2
source

Try http://repo.xposed.info/module/com.brandonnalls.mockmocklocations

Some applications will not allow you to use them if "Allow location layout" even if you do not scoff at your location. This helps prevent apps from detecting Enable Layouts.

+2
source

Source: https://habr.com/ru/post/948498/


All Articles