I've searched through some topics but haven't found an answer. I need not to specify lat/long but turn the switch of allowing mock locations.
Asked
Active
Viewed 6,263 times
7
-
Possible duplicate of [Set a mock GPS location on an Android device](http://stackoverflow.com/questions/25976506/set-a-mock-gps-location-on-an-android-device) – sonictt1 Apr 08 '16 at 14:50
-
Check also: http://stackoverflow.com/questions/39753097/how-to-set-allow-mock-location-on-android-device-before-executing-androidtest-wi/39765423#39765423 – Daniele Sep 29 '16 at 08:40
1 Answers
9
In Marshmallow (and above) after you have installed your app, just run:
adb shell appops set com.example.my.package android:mock_location allow
hope this helps!
Some internals: the string android:mock_location is resolved by the AppOpsManager into an actual int and than executed.

Francesco Pez
- 676
- 5
- 7
-
Is there any way to execute this via android test? Like in a setup method annotated with before(). I don't want to use adb for that. Any suggestion? I need to run it automatically before executing the test itself. – Daniele Sep 28 '16 at 17:15
-
1
-
1Anybody found way to change allow mock location settings in pre-marshmallow? – chikka.anddev Apr 24 '17 at 14:24
-
1
-
@chikka.anddev I think you are looking for this command: `adb shell settings put secure mock_location 1` Use 1 to enable and 0 to disable. – penguin359 Jan 13 '22 at 07:46