17

I have a rooted phone. Is it possible to enable location services (GPS or network location) via ADB or Terminal Emulator?

0
16

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
1
  • 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 – Suban Dhyako Sep 11 '18 at 10:07
5

Android location service comes with different options:

  1. 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
  2. Phone only: gps

    • Enable: adb shell settings put secure location_providers_allowed +gps
    • Disable: adb shell settings put secure location_providers_allowed -gps
  3. Battery saving: network

    • Enable: adb shell settings put secure location_providers_allowed +network
    • Disable: adb shell settings put secure location_providers_allowed -network
4

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() and LocationManager#MODE_CHANGED_ACTION.

Don't know what a programmatic way to do this through the shell will be once this constant disappears.

3
  • Enable: adb shell settings put secure location_mode 3
  • Disable: adb shell settings put secure location_mode 0

See Stack Overflow - How to enable/disable GPS location services on Android 9 via ADB commands (not rooted device).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.