18

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

Andrew T.
  • 15,988
  • 10
  • 74
  • 123
theodm
  • 1,087
  • 5
  • 13
  • 25

4 Answers4

20

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
Aditya S
  • 301
  • 2
  • 2
  • 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
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
Andrew T.
  • 15,988
  • 10
  • 74
  • 123
Parth Naik
  • 71
  • 1
  • 1
5

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.

anotherdave
  • 151
  • 1
  • 2
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).

Andrew T.
  • 15,988
  • 10
  • 74
  • 123
CoolMind
  • 141
  • 2