13

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
11

Is it possible to enable Location Services(GPS or Google NetworkLocation) via ADB or Terminal Emulator?

The command is:

adb shell settings put secure location_providers_allowed gps

where,

  • settings would makes changes into settings.db (part of com.android.providers.settings)
  • put is to update key location_providers_allowed with value gps in table secure.

The aforesaid command wouldn't enable Google's Location Service. In order to enable it as well, issue the command:

adb shell settings put secure location_providers_allowed gps,network

You would be shown a popup to agree for Location Services. In my Android 4.2.1, I have to agree through GUI or input keyevent every time I enable the service from scratch.

                                                                    IMG: 4.2.1

However, in my Android 5.0 I can save the settings in the dialog and the command execution makes the things done perfectly from the next time.

                                                                    IMG: 5.0

Some devices like Lollipop ones have three Locations modes, and the relevant values to be passed in the aforesaid command would be:

  • High accuracy: gps,wifi,network or gps,network (if you don't want Wi-Fi enabled)
  • Battery saving: wifi,network or network only
  • Device only: gps

To disable Location mode

adb shell settings put secure location_providers_allowed ' '

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

See :

But I already gave a big idea using settings put.

  • Would it be possible to achieve the same, but from the device's console, not via an external computer's ADB? – davide Aug 16 '15 at 11:09
  • 1
    Yes, absolutely. You would need root access or ADB wireless running on the device though. Take a look at this answer as an example. You would get an idea. – Firelord Aug 16 '15 at 12:01
  • This used to work on Android 5, but it doesn't anymore on Android 6. With or without root the setting does not change and stays the same as is configured on the system. It probably has something to do with location_providers_allowed being deprecated (developer.android.com/reference/android/provider/…). Ideas? – gw0 Nov 4 '15 at 7:45
  • If you just want to turn on/off GPS functionality, you can go to the settings Location page, then click the switch button. This operation also can be achieved by command: adb shell am start -a android.settings.LOCATION_SOURCE_SETTINGS, then click the switch button. – Eddy Jan 5 '16 at 2:58
12

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

  • 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

0

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.

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.