我在 app_restrictions.xml 中有这个:
<restriction
android:key="int1"
android:restrictionType="integer"
android:defaultValue="0"
/>
现在,如果我想阅读它,我会得到
> java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
我尝试过:
RestrictionsManager rm = getApplicationContext().getSystemService(Context.RESTRICTIONS_SERVICE);
Integer val1 = rm.getApplicationRestrictions().getInt("int1");
我读取 boolean 值或字符串没有问题。 Google 没有提供 Integer 的示例。整数限制类型是否可用?如果是这样:怎么办?
最佳答案
getInt() 按预期工作。 问题似乎出在测试 DPC 上。 我没有为测试 DPC 中的类型选择限制选择正确的类型。测试 DPC 中并不真正支持选择。您必须输入一个值并选择它的类型。也许整数值对于选择限制根本不起作用。稍后我将尝试使用真正的 MDM 系统...
关于java - 如何在有限制的情况下使用 getInt()(托管配置)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56836646/