app_restrictions.xml 是 Android 应用实现受管理配置的关键文件,必须置于 res/xml/app_restrictions.xml 路径,并在 AndroidManifest.xml 的 标签下通过 声明;根元素为 ,每个 需指定 android:key、android:title、android:defaultValue 和 android:type,且类型写法须严格匹配规范。
app_restrictions.xml 是 Android 应用实现受管理配置(Managed Configuration)的关键文件,用于向企业移动管理(EMM)系统声明你的应用支持哪些可远程配置的选项。它不是随便写个 XML 就能生效,结构、位置和引用方式都必须准确。
这个文件必须放在 res/xml/app_restrictions.xml 路径下(注意是小写 xml 目录,不是 Xml 或 XML)。同时,你得在 AndroidManifest.xml 的 标签下添加声明:
缺了这行,IT 管理员或 EMM 工具根本读不到你的配置定义。
文件根元素必须是 ,每个可配项用一个 子元素表示。每个 restriction 必须包含以下属性:
"enable_offline_mode"
@string/restrict_title_offline)android:type
boolean、integer、string、choice、multiselect、bundle 等例如定义一个开关和一个下拉选项:
不同类型要注意
写法细节:
,且每个 entry 的 android:value 必须是纯字符串(不能含空格或特殊字符),供代码解析用android:defaultValue="100" 或 android:defaultValue="default_server"
"true" 或 "false"(注意是字符串,不是 true/false 字面量)res/values/strings.xml 中,方便多语言适配编译后检查 APK 是否真包含该文件:
res/xml/app_restrictions.xml
adb shell dumpsys restrictions
基本上就这些。不复杂但容易忽略细节,尤其是大小写和资源路径。