According API documentation a device owner app can modify a few "secure settings" and specially the LOCATION_MODE with the following call :
devicePolicyManager.setSecureSetting (ComponentName admin,
String setting,
String value)
Called by profile or device owners to update Settings.Secure settings [...]
A device owner can additionally update the following settings: LOCATION_MODE
According my understanding the value of LOCATION_MODE is an int (resp. 0 for location disabled, 1 for GPS only, 2 for battery saving mode and 3 for high accuracy).
My problem is the type of the String value
parameter. LOCATION_MODE requires an int, but the API requires a String.
Did I miss something ?
Solution is simply to use the String representation of the int value.
For instance to enable "gps only" location mode :
[Thanks to @Selvin comment]
It make sense, because when digging into javadoc for LOCATION_MODE, you can read :