Enable GPS in a device owner app

前端 未结 1 734
醉话见心
醉话见心 2021-01-15 06:18

According API documentation a device owner app can modify a few \"secure settings\" and specially the LOCATION_MODE with the following call :

devicePolicyMan         


        
相关标签:
1条回答
  • 2021-01-15 07:07

    Solution is simply to use the String representation of the int value.

    For instance to enable "gps only" location mode :

    DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    if (dpm.isDeviceOwnerApp(context.getPackageName())) {
        ComponentName componentName = new ComponentName(context, MyDeviceAdmin.class);
        dpm.setSecureSetting(componentName, Settings.Secure.LOCATION_MODE, String.valueOf(Settings.Secure.LOCATION_MODE_SENSORS_ONLY));
    }
    

    [Thanks to @Selvin comment]

    It make sense, because when digging into javadoc for LOCATION_MODE, you can read :

    Note that internally setting values are always stored as strings[...]

    0 讨论(0)
提交回复
热议问题