Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't set value of location_providers_allowed using "adb shell settings put"

Tags:

android

adb

I'm trying to turn location on using the following commands:

adb shell settings put secure location_providers_allowed gps,wifi,network
adb reboot

But it's neither changing the value of the variable location_providers_allowed nor turning it on under Android Settings UI after the reboot.

I tried the same command to set other variables, like mock_location, and it worked without problems. Is this variable not possible to be changed?

Android version: M

like image 452
Marcelo Avatar asked Dec 29 '25 13:12

Marcelo


2 Answers

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

like image 85
Aditya S Avatar answered Dec 31 '25 03:12

Aditya S


I have yet to solve this problem, but wanted to provide additional information that I feel is relevant and may help somebody else solve this.

I tried to follow this, but it was mentioned in one of the comments that:

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/…) – gw0 Nov 4 '15 at 7:45

I looked into the docs for Settings.Secure location_providers_allowed and sure enough:

This constant was deprecated in API level 19. use LOCATION_MODE and MODE_CHANGED_ACTION (or PROVIDERS_CHANGED_ACTION)

I tried to set location_mode but had no effect on enabling/disabling location services.

When turning on/off location services manually through the location_providers_allowed flag is affected, not location_mode. I find it weird that the docs say it's deprecated, but it's still used and location_mode isn't.

That's all I got.

like image 21
ejwessel Avatar answered Dec 31 '25 04:12

ejwessel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!