问题:在 app_restrictions.xml 中实施应用限制和 Lint 错误

Issue: Implementing app restrictions and Lint Errors in app_restrictions.xml

我正在研究 Android MDM,app_restrictions.xml 文件位于 /src/main/res/xml/ 文件夹下。我使用的 MDM 没有显示限制值,甚至没有显示默认值。已遵循此 link 中提到的所有步骤来设置应用程序限制:https://developer.android.com/training/enterprise/app-restrictions.html 但我收到 Bundle[EMPTY_PARCEL]。下面是代码

app_restrictions.xml

<?xml version="1.0" encoding="utf-8"?>
<restrictions xmlns:android="http://schemas.android.com/apk/res/android">
<restriction
android:key="MDMEmailKey"
android:title="Email"
android:restrictionType="string"
android:description="@string/email_address_mdm_description"
android:defaultValue="testtesttest@gmail.com" />
<restriction/>
</restrictions>

此外,lint 向我显示以下错误,尽管我能够通过 lint 选项在 gradle 中抑制它,但只是想知道这是否不是我面临的问题的原因。请告诉我为什么会出现这些错误。

Executing task ':project_name:lintVitalRelease' (up-to-date check took 0.0 secs) due to:
  Task has not declared any outputs.
.../src/main/res/xml/app_restrictions.xml:8: Error: Missing required attribute android:key [ValidRestrictions]
    <restriction/>
    ~~~~~~~~~~~~~~
.../src/main/res/xml/app_restrictions.xml:8: Error: Missing required attribute android:restrictionType [ValidRestrictions]
    <restriction/>
    ~~~~~~~~~~~~~~
.../src/main/res/xml/app_restrictions.xml:8: Error: Missing required attribute android:title [ValidRestrictions]
    <restriction/>
    ~~~~~~~~~~~~~~

   Explanation for issues of type "ValidRestrictions":
   Ensures that an applications restrictions XML file is properly formed

   https://developer.android.com/reference/android/content/RestrictionsManager.html

3 errors, 0 warnings

回复:lint 错误 您在第 8 <restriction/> 行有一个空的 restriction 元素 只需删除它,lint 错误就会消失。

<?xml version="1.0" encoding="utf-8"?>
<restrictions xmlns:android="http://schemas.android.com/apk/res/android">
<restriction
android:key="MDMEmailKey"
android:title="Email"
android:restrictionType="string"
android:description="@string/email_address_mdm_description"
android:defaultValue="testtesttest@gmail.com" />
<restriction/> <!-- Error here -->
</restrictions>