I know how to set locatlon for emulators using device configuration interface from Motodoev Studio for example. But, how I can set locatlon for a device?
3 Answers
this is possible using ADB shell:
$ telnet localhost 5554
Android Console: type 'help' for a list of commands
OK
geo fix -82.411629 28.054553
OK
Please read: https://stackoverflow.com/a/2587369/950427
-
isn't this for a device? AFAIK, there is no way to set the location other than mock the location on your device, and add a test location provider. Jul 14, 2013 at 17:39
-
Yes, I believe this is what he was looking for. What is your question? Jul 14, 2013 at 18:57
-
6Down vote because OP is explicitly asking about on a Device. This only works for the Emulator.– cdeJul 14, 2016 at 17:05
-
@cde I answered this question 3.5+ years ago. It helped OP at the time. Jul 15, 2016 at 14:13
Alternatively what might also be an option here is to use Appium's io.appium.setting's app.
Once that app's installed on the device you can give it permissions and mock location through adb like this:
adb shell pm grant io.appium.settings android.permission.READ_PHONE_STATE
adb shell pm grant io.appium.settings android.permission.WRITE_SETTINGS
adb shell pm grant io.appium.settings android.permission.ACCESS_FINE_LOCATION
adb shell pm grant io.appium.settings android.permission.ACCESS_COARSE_LOCATION
adb shell pm grant io.appium.settings android.permission.ACCESS_MOCK_LOCATION
adb shell pm grant io.appium.settings android.permission.SET_ANIMATION_SCALE
adb shell pm grant io.appium.settings android.permission.CHANGE_CONFIGURATION
adb shell am start -W -n io.appium.settings/.Settings -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000
adb shell appops set io.appium.settings android:mock_location allow
adb shell am startservice -e longitude 28 -e latitude 77 io.appium.settings/.LocationService;
For more info on the app and some other intents check out their readme
Alternative to @jmp answer, I can recommend to use instead of Appium's app the FakeTraveler It has not the disadvantage to run a lot of adb
permission commands, which not really work out of the box and without search google why setting permission ACCESS_MOCK_LOCATION don't work.
FakeTraveler guides you automatic to right developer setting ♥
-
AFAIK, there are many mock location apps out there, but those don't really answer the question of changing the location using ADB. Does this app allow controlling the location using ADB?– Andrew T. ♦Dec 23, 2021 at 18:19