16

Is it possible to enable Location Services(GPS or Google NetworkLocation) via ADB or Terminal Emulator? I'm on a rooted Phone.

Extra Points: Is it also possible to change other system-related settings?

  • This question already has been asked, see: Can I change some Android settings from the command line? – Izzy Feb 22 '13 at 16:57
  • 2
    @Izzy I don't think that's fully a duplicate. – Matthew Read Feb 22 '13 at 17:37
  • 2
    @Izzy not related. The question you linked to has nothing to do with location services. – lorddev Dec 11 '13 at 20:05
  • 1
    @lorddev No, they are not explicitly mentioned. But you can use the same code to call the intent for location services. What confuses me a little is the phrasing of my comment, which suggests a "direct hit" (and here you're both correct: it's not exactly the same). Hard to say, half a year later, what I had in mind back then... – Izzy Dec 11 '13 at 20:27
15

For Android 6.0

To Enable use :

For GPS : adb shell settings put secure location_providers_allowed +gps

For Network : adb shell settings put secure location_providers_allowed +network

To Disable :

GPS : adb shell settings put secure location_providers_allowed -gps

For Network : adb shell settings put secure location_providers_allowed -network

| improve this answer | |
  • This worked for me, not the accepted answer. – Matt D Jul 18 '18 at 14:06
  • 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
4

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

| improve this answer | |
3

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.

| improve this answer | |

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.