【问题标题】:Issue: Implementing app restrictions and Lint Errors in app_restrictions.xml问题:在 app_restrictions.xml 中实施应用限制和 Lint 错误
【发布时间】:2016-02-03 13:19:17
【问题描述】:

我正在开发 Android MDM,并且在 /src/main/res/xml/ 文件夹下有 app_restrictions.xml 文件。我使用的 MDM 没有显示限制的值,甚至没有显示默认值。已按照此链接中提到的所有步骤设置应用程序限制: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

【问题讨论】:

标签: android lint android-lint airwatch


【解决方案1】:

RE:lint 错误 您在第 8 行有一个空的 restriction 元素 &lt;restriction/&gt; 只需删除它,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>

【讨论】:

  • 感谢 Nagesh,这解决了 lint 错误,但您知道为什么我在 Bundle appRestrictions = myRestrictionsMgr.getApplicationRestrictions(); 处得到空包裹,即使我已经通过 MDM 下载了我的应用程序。
  • 这是例外吗?您也可以试试developer.android.com/samples/AppRestrictionSchema/… 中列出的示例应用程序
猜你喜欢
  • 1970-01-01
  • 2014-06-21
  • 1970-01-01
  • 1970-01-01
  • 2016-03-08
  • 2021-12-05
  • 1970-01-01
  • 1970-01-01
  • 2016-02-27
相关资源
最近更新 更多