在设备所有者应用中启用GPS [英] Enable GPS in a device owner app

查看:434
本文介绍了在设备所有者应用中启用GPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 API文档设备所有者应用可以修改一些安全设置,特别是 LOCATION_MODE 进行以下调用:

  devicePolicyManager.setSecureSetting(ComponentName admin,
字符串设置,
字符串值)



< blockquote>

由个人资料或设备所有者调用以更新Settings.Secure设置
[...]



设备所有者可以另外更新以下设置:
LOCATION_MODE

根据我的理解,LOCATION_MODE的值是一个int(对于loca分别为0 我的问题是字符串值的类型参数。 LOCATION_MODE需要一个int,但是API需要一个字符串。



我错过了什么? 解决方案



例如,启用gps only位置模式:



  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));






[感谢@Selvin评论]



它是有道理的,因为当挖掘到javadoc的 LOCATION_MODE ,你可以阅读:


请注意,内部设置值始终以字符串存储[...]


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 :

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[...]

这篇关于在设备所有者应用中启用GPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆