18

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

0

4 Answers 4

19

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
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 Sep 11, 2018 at 10:07
7

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.

4
  • 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).

2
  • Functions on Android 11.
    – user598527
    Jun 20, 2022 at 6:39
  • @user598527, hi! Thanks for the comment. Currently I don't know.
    – CoolMind
    Jun 20, 2022 at 6:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .