termux-mockgps is a lightweight POSIX shell command for controlling the Android MockGPS application directly from Termux.
It is intentionally small: there is no local database, no configuration framework, and no additional Termux package dependencies. The command uses the Android am command to communicate with MockGPS.
This project is the command-line frontend for the Android application:
The two projects are designed to work together.
termux-mockgps sends commands to the exported MockGPS broadcast receiver and, where appropriate, starts or stops the Android foreground service.
MockGPS contains the actual location-mocking implementation and is responsible for storing the mock coordinates and managing Android's test providers.
- Start MockGPS from Termux.
- Start at the last saved location or specify coordinates.
- Change mock coordinates while MockGPS is running.
- Stop mocking and restore normal location operation.
- Enable or disable MockGPS boot restoration.
- Enable or disable location drift.
- Open the MockGPS Android application.
- Optional toast suppression with
-notoast. - POSIX
shimplementation. - No additional Termux package dependencies.
termux-mockgps is designed specifically for the current BuriXon-code/MockGPS Android application.
It is intended for:
- Termux on Android.
- Android 10 or newer for the current MockGPS setup.
- The matching MockGPS Android application installed.
- MockGPS selected as the system mock-location application.
The script itself is portable POSIX sh, but it depends on Android's am command and the MockGPS application interface, so it is not a generic desktop Linux location-mocking command.
There are no additional Termux package dependencies.
You do not need to install packages such as python, termux-api or whatever.
The script uses:
- POSIX shell functionality provided by the Termux environment.
- Android
amfor starting services and sending broadcasts. - Android
pmto check whether MockGPS is installed.
Note
The script uses Android pm commands because the ones in Termux don't work properly.
The script automatically looks for am in the normal Termux/Android locations.
Clone the repository:
git clone https://github.com/BuriXon-code/termux-mockgps.git
cd termux-mockgpsCopy the command into Termux's executable directory:
cp termux-mockgps "$PREFIX/bin/termux-mockgps"
chmod +x "$PREFIX/bin/termux-mockgps"Verify it:
termux-mockgps helpYou can also run the script directly from the repository:
./termux-mockgps helpBefore using the command, configure the companion MockGPS application.
Open:
Settings
→ Apps
→ MockGPS
→ Permissions
→ Location
Grant location access.
Open:
Settings
→ Apps
→ MockGPS
→ Notifications
Enable notifications.
Open:
Settings
→ Developer options
→ Select mock location app
Select:
MockGPS
Without this configuration Android will reject the injected test locations.
usage: termux-mockgps <command> [options]
Commands:
start [lat lon] Start mocking a location.
set <lat lon> Set the mock location.
boot <0|1|on|off> Enable or disable mocking on device boot.
drift <0|1|on|off> Enable or disable location drift.
open Open the MockGPS application.
stop Stop mocking and restore normal location.
help Show this help message.
version Show version information.
Location:
Coordinates can be specified as:
50.06143 19.93658
50.06143,19.93658
-lat:50.06143 -lon:19.93658
Boot:
Values:
1|on Enable mocking on boot.
0|off Disable mocking on boot.
Options:
-notoast Do not display toast notification.
Start MockGPS using its last stored location:
termux-mockgps startStart at a specific location:
termux-mockgps start 50.06143 19.93658Negative coordinates are supported:
termux-mockgps start -50.06143 -19.93658Explicit coordinate options are supported too:
termux-mockgps start -lat:50.06143 -lon:19.93658Change the mock location:
termux-mockgps set 50.06143 19.93658Comma-separated coordinates are also supported:
termux-mockgps set 50.06143,19.93658Or use explicit options:
termux-mockgps set -lat:50.06143 -lon:-19.93658When MockGPS is running, the new coordinates are applied automatically.
When MockGPS is stopped, the new coordinates are stored by the Android application and used by the next start command.
Suppress the command-related toast:
termux-mockgps set 50.06143 19.93658 -notoastStop the MockGPS foreground service and disable persistent operation:
termux-mockgps stopThe Android application remains installed and keeps its stored coordinates.
Enable restoration after Android boot:
termux-mockgps boot onThe following forms are also accepted:
termux-mockgps boot 1
termux-mockgps boot enable
termux-mockgps boot trueDisable it:
termux-mockgps boot offor:
termux-mockgps boot 0Boot restoration itself is implemented by MockGPS. The Termux command only changes the corresponding application state through the broadcast interface.
Enable small simulated movement around the selected location:
termux-mockgps drift onDisable it:
termux-mockgps drift offOther accepted forms include 1, 0, enable, disable, true, and false.
The drift implementation belongs to the MockGPS Android service.
Open the MockGPS Android application:
termux-mockgps openThis uses the application's launcher activity.
Note
The -notoast option has no effect on start/stop commands because they do not send commands via droadcast.
Show the installed script version:
termux-mockgps versionCurrent script version:
1.0.0
The important part of the project is its integration with MockGPS through Android's command interface.
Conceptually:
Termux
│
├── start/stop service commands
│
└── broadcasts
│
▼
MockGPS / MockGpsReceiver
│
▼
MockLocationService
│
▼
Android test location providers
The companion script uses the MockGPS package:
dev.burixon.mockgps
and the Android components:
.MockLocationService
.MockGpsReceiver
This is why termux-mockgps is intended specifically for the matching MockGPS repository rather than as a standalone generic GPS utility.
MockGPS exposes an external broadcast control interface. This is the key integration point between the two repositories.
The receiver is:
dev.burixon.mockgps.MockGpsReceiver
Supported command values include:
on
set
off
drift
The receiver also accepts state-changing extras for boot restoration and notification behavior.
The Android application has a Broadcast commands switch. When that option is disabled, MockGPS ignores external broadcast commands.
Because the Termux script relies on this interface, the switch must remain enabled when using termux-mockgps for remote control.
The Termux script does not maintain a coordinate database or local coordinate file.
The Android MockGPS application stores the selected latitude and longitude itself.
This means:
termux-mockgps startcan reuse the last location selected from the Android application or previously sent through termux-mockgps set.
MockGPS owns the foreground-service notification.
The Termux command can optionally suppress command-related toast messages with:
-notoastFor example:
termux-mockgps start -notoastThe script passes the corresponding setting to the Android application.
Install the companion Android application:
https://github.com/BuriXon-code/MockGPS
The script could not find Android's am utility. This usually means the command is not being run inside a normal Android/Termux environment.
Check that:
1. MockGPS is installed.
2. MockGPS is selected as the mock-location application.
3. Location permission is granted.
4. Broadcast commands are enabled inside MockGPS.
Make sure the MockGPS foreground service is still running and that the application is configured as the mock-location provider.
Check the application's Start on boot setting, or enable it with:
termux-mockgps boot onAndroid OEM battery and background restrictions may also affect automatic restoration.
Android application:
This repository provides the Android-side implementation, including:
- map-based location selection,
- mock providers,
- foreground service,
- persistent state,
- reboot restoration,
- external broadcast control.
- MockGPS: https://github.com/BuriXon-code/MockGPS
- termux-mockgps: https://github.com/BuriXon-code/termux-mockgps
- Website: https://burixon.dev/MockGPS/
- Bug reports: https://burixon.dev/bugreport/#termux-mockgps
- Contact: https://burixon.dev/contact/
- Donations: https://buycoffee.to/burixon-code
GPL-3.0.
See LICENSE for the full license text.
For any issues, suggestions, or questions, reach out via:
- Email: support@burixon.dev
- Contact form: Click here
- Bug reports: Click here
If you find this script useful, consider supporting my work by making a donation:
Your contributions help in developing new projects and improving existing tools!
