Developers, testers, and privacy‑conscious users often need to make an Android device think it is somewhere else. Common scenarios include:
Android’s built‑in Mock location capability lets you feed arbitrary coordinates to the system. When combined with adb, you can script precise movements, repeatable test cases, or one‑off location swaps—all without rooting.
Note: Mock locations affect all apps that request location data. Some apps (e.g., banking, payment, or certain games) may refuse to run if they detect mock locations. Use this feature responsibly and revert to real GPS when finished.
Build number seven times, then Settings > System > Developer options > USB debugging.Android requires you to designate a single app as the “mock location provider”. We’ll use a tiny helper app that does nothing but expose an interface for ADB.
android.permission.ACCESS_MOCK_LOCATION permission works; Mock GPS Provider is a popular free choice.Start button.Warning: Selecting a mock location app disables the device’s real GPS for all apps. Remember to switch back to “None” when you finish testing.
ADB can feed location updates in two main formats:
For most testing, a simple CSV file is enough. Create a file called mock_locations.txt on your computer with the following layout (one entry per line):
latitude,longitude,accuracy,provider
37.4219983,-122.084,5,gps
40.712776,-74.005974,10,gps
-33.868820,151.209296,8,gps
Explanation of columns:
latitude and longitude – decimal degrees.accuracy – radius in meters; typical GPS accuracy is 5–10 m.provider – usually gps or network. Using gps mimics the hardware GPS.If you prefer a GPX file, you can export a track from tools like GPS Visualizer and save it as track.gpx. The ADB command we’ll use later can read both formats.
We’ll place the file in the mock provider’s private storage so the app can read it. The exact path varies by app, but most expose a public /sdcard/MockLocation folder.
adb devices
You should see your device listed as device. If it shows unauthorized, accept the prompt on the phone.
adb shell mkdir -p /sdcard/MockLocation
adb push mock_locations.txt /sdcard/MockLocation/
If you are using a GPX track, push it with the same command, e.g., adb push track.gpx /sdcard/MockLocation/.
The helper app we installed listens for a broadcast intent that tells it to start feeding locations. The intent name is com.example.mockgps.START (replace com.example.mockgps with the actual package name of your chosen app; you can find it with adb shell pm list packages | grep mockgps).
Assuming the package is com.lexa.mockgps, run:
adb shell am broadcast -a com.lexa.mockgps.START \
--es file "/sdcard/MockLocation/mock_locations.txt"
This command does three things:
START action to the mock app.file extra.After a few seconds, you should see a toast notification from the mock app saying “Mock locations active”.
There are several ways to confirm that Android is using the fake coordinates.
adb shell dumpsys location | grep "Location" -A 5
Look for lines showing the latitude and longitude you supplied.
If the location does not change, double‑check that the mock app is still running (pull down the notification shade and look for its persistent icon). Also verify that you selected the correct mock location app in Developer options.
By default the mock app emits one update per second. For smoother movement or slower testing you can control the interval.
Many mock apps expose an extra intent field called interval (milliseconds). Example to emit a location every 5 seconds:
adb shell am broadcast -a com.lexa.mockgps.START \
--es file "/sdcard/MockLocation/mock_locations.txt" \
--ei interval 5000
If you supplied a GPX track, the app usually respects the timestamps inside the file, reproducing the original speed. Some apps also let you set a speed multiplier via an extra named speed_factor.
When you’re done, send a stop broadcast:
adb shell am broadcast -a com.lexa.mockgps.STOP
Or simply close the mock app on the phone. After stopping, Android will revert to the real GPS signal (if you have a clear view of the sky).
geo fix Directly from ADBIf you prefer not to install any third‑party app, ADB itself can inject a single location using the geo fix command. This works on emulators and, on many real devices, via the adb shell “telnet” interface. The syntax is:
adb emu geo fix <longitude> <latitude> [<altitude>] [<accuracy>]
Example:
adb emu geo fix -122.084 37.4219983 0 5
Limitations:
geo service (rare on production phones).For most physical devices, the mock‑location app approach described earlier is more reliable.
adb logcat | grep MockGPS after sending the START intent. Look for a line like “MockGPS: Started with file …”.adb root only on devices that allow it (most production phones do not). Instead, push to a public folder like /sdcard/ as shown.adb shell ls -l /sdcard/MockLocation/
ACCESS_FINE_LOCATION from the LocationManager will receive the mock data, but apps that use Google Play Services’ fused location provider may ignore mock sources unless the device is in “developer mode”. Ensure Allow mock locations is enabled in Developer options (this is automatic when you pick a mock app).Location.isFromMockProvider(), it will know the location is fake. In that case, you cannot hide the fact without rooting.adb shell input tap … to script end‑to‑end scenarios for location‑aware apps.adb shell rm -rf /sdcard/MockLocation
After these steps, your phone will use the real GPS again, and any location‑dependent services will function normally.
By enabling a mock location app, preparing a simple coordinate file, and using ADB broadcasts, you can reliably simulate GPS positions on any Android device without rooting. This workflow gives you fine‑grained control, works across manufacturers, and integrates cleanly with automated testing pipelines. Remember to revert the mock settings when finished to avoid unexpected behavior in everyday apps.









