I have a rooted phone. Is it possible to enable location services (GPS or network location) via ADB or Terminal Emulator?
4 Answers
On Android 6.0,
To enable:
- GPS:
adb shell settings put secure location_providers_allowed +gps
- Network:
adb shell settings put secure location_providers_allowed +network
To disable:
- GPS:
adb shell settings put secure location_providers_allowed -gps
- Network :
adb shell settings put secure location_providers_allowed -network
On Android 11.0,
To enable:
- GPS:
adb shell settings put secure location_mode 3
To disable:
- GPS:
adb shell settings put secure location_mode 0
-
Thanks, it works. Is there anyway we can enable/disable gps and network with one line adb command. I need it for high accuracy locaton. gps+network =high accuracy Sep 11, 2018 at 10:07
Android location service comes with different options:
High accuracy:
gps, network
- Enable:
adb shell settings put secure location_providers_allowed +gps,network
- Disable:
adb shell settings put secure location_providers_allowed -gps,network
- Enable:
Phone only:
gps
- Enable:
adb shell settings put secure location_providers_allowed +gps
- Disable:
adb shell settings put secure location_providers_allowed -gps
- Enable:
Battery saving:
network
- Enable:
adb shell settings put secure location_providers_allowed +network
- Disable:
adb shell settings put secure location_providers_allowed -network
- Enable:
location_providers_allowed
no longer works for Android 10 (API level 29).
Instead, you can set the location_mode
to LOCATION_MODE_HIGH_ACCURACY
with a value of 3:
adb shell settings put secure location_mode 3
NOTE: Probably won't work >v29 as this is already deprecated as the docs on Location Mode mention:
This constant was deprecated in API level 28. The preferred methods for checking location mode and listening for changes are via
LocationManager#isLocationEnabled()
andLocationManager#MODE_CHANGED_ACTION
.
Don't know what a programmatic way to do this through the shell will be once this constant disappears.
- Enable:
adb shell settings put secure location_mode 3
- Disable:
adb shell settings put secure location_mode 0