java - 如何在有限制的情况下使用 getInt()(托管配置)?

标签 java android android-restrictions

我在 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/

相关文章:

IDEA Gradle Sync 上的 Java 主目录不同

java - 如何从 aerospike Java cilent 获取列表然后在单个事务中修改列表类型的 bin

android - 布局已经存在使用不同的限定符

android - 更改android中编辑文本框的外观

android - IT 管理员如何使用托管配置配置 Android 应用

android - RestrictionManager getRestrictions() 始终为空

java - 从循环(Arraylist)和几个单独的标志到mysql命令行制作一个字符串

java - 无法在类路径上找到 apply/clojure/core/vector__init.class 或 apply/clojure/core/vector.clj

android - Android Studio 上的实验性 NDK 支持