Can't Set Value Of Location_providers_allowed Using "adb Shell Settings Put"
Solution 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.Securelocation_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.
Solution 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
Solution 3:
From Android 6 up-to Android 9 you can manipulate "location_providers_allowed" if you have WRITE_SECURE_SETTINGS permission.
From Android 10, this has no effect whatsoever as described here (search Android Q): https://developer.android.com/reference/android/provider/Settings.Secure#LOCATION_PROVIDERS_ALLOWED
There is a new API, but it doesn't have any public way to change any settings: https://developer.android.com/reference/android/location/LocationManager#isProviderEnabled(java.lang.String)
Maybe with root or as system app, one can access this:
@SystemApi@TestApi@RequiresPermission(WRITE_SECURE_SETTINGS)
public void setProviderEnabledForUser(String provider, boolean enabled, @NonNull UserHandle userHandle);
EDIT: This work perfectly as system app. Haven't tried with root.
Solution 4:
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
Post a Comment for "Can't Set Value Of Location_providers_allowed Using "adb Shell Settings Put""