Can't set value of location_providers_allowed

2019-07-20 04:12发布

问题:

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

回答1:

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.



回答2:

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



回答3:

I solved this by pulling /data/system/users/0/settings_secure.xml

change value in the xml of the setting below to gps,network or what you want

<setting id="0" name="location_providers_allowed" value="" package="android" />

than push it back to same place and reboot



标签: android adb