企业Android应用配置-应用限制-无法按预期运行

确实可以使用一些指南来调试/解决我遇到的问题。

我构建了第一个应用程序,该应用程序旨在由企业MDM / EMM服务进行配置。我创建了app_restrictions.xml文件,并设置了捆绑包,以便从该文件中读取限制。

在连接到计算机的设备上以调试方式运行时,我可以成功读取XML文件中的所有值

但是,一旦我将其投入生产,就会出现问题。

我已将应用发布到Play商店,并将该应用添加到EMM / MDM。

我可以看到所有托管配置设置都出现在EMM / MDM中-到目前为止,我已经掌握了一切。

但是,一旦将应用程序以其他配置推送到设备后,读取的值就不是来自EMM / MDM的自定义值-它们是我在开发的XML中的默认值。

在该过程的这一部分进行故障排除时,我找不到任何好的资源。

有人做过这个吗?

xtren2008 回答:企业Android应用配置-应用限制-无法按预期运行

使用此方法时:getManifestRestriction限制管理器会获得XML应用程序的限制,但是当您使用此方法时:getApplicationRestrictions该应用程序会从您的EMM / MDM中读取限制,因此,您还必须配置广播接收者,以监听您政策的任何变化。

另一件事:对于我而言,我必须创建一个具有所有应用程序限制的共享首选项,以保存当前设置并避免该设备在重启后清除它们。

,

我最近创建了很多 B2B 应用程序,让客户能够在每个设备或每个部署的基础上自定义应用程序至关重要。

这是我将应用配置设置添加到您的应用程序中以便任何 MDM 能够通过托管 Google Play 商店利用这些设置的指南:

清单: 您必须在该部分中包含此内容:

        <meta-data android:name="android.content.APP_RESTRICTIONS"
        android:resource="@xml/app_restrictions" />

app_restrictions.xml 此文件将保留您的应用程序限制。应用程序限制只有几个选项,但您可以通过各种不同的创造性方式进行这项工作。这是一组基本的限制:

<restrictions xmlns:android="http://schemas.android.com/apk/res/android">

    <restriction
    android:key="LicenseKey"
    android:title="@string/LicenseKey"
    android:restrictionType="string"
    android:description="@string/LicenseKey_Description"
    android:defaultValue="" />

    <restriction
    android:key="Section1"
    android:title="Settings"
    android:restrictionType="bundle">

        <restriction
        android:key="Setting1"
        android:title="Setting 1"
        android:description="More descriptive description here"
        android:restrictionType="choice"
        android:entryValues="@array/setting_1_array_values"
        android:entries="@array/setting_1_array_choices"
        android:defaultValue="@string/setting_1"/>

        <restriction
        android:key="Setting2"
        android:title="Setting 2"
        android:description="More descriptive description here"
        android:restrictionType="string"
        android:defaultValue="Some default string value here" />

        <restriction
        android:key="Setting3"
        android:title="Setting 3"
        android:description="More descriptive description here"
        android:restrictionType="integer"
        android:defaultValue="20" />

</restriction>

<restriction
    android:key="Section 2"
    android:title="Group things in more sections to make it easier to manage if you have lots of settings"
    android:restrictionType="bundle">

        <restriction
        android:key="Setting4"
        android:title="Setting 4"
        android:description="More descriptive description here"
        android:restrictionType="integer"
        android:defaultValue="20" />

        <restriction
        android:key="Setting5"
        android:title="Setting 5"
        android:description="More descriptive description here"
        android:restrictionType="integer"
        android:defaultValue="20" />

</restriction>

对于您的某些限制,您可能需要下拉样式选择器中的预定义项目列表 - 如上所示,您可以为此使用一个数组并将以下内容放入您的 Strings.xml

Strings.xml:

<string-array name="setting_1_array_choices">
    <item>"Choose This for Option A"</item>
    <item>"Choose This for Option B"</item>
</string-array>
<string-array name="setting_1_array_values">
    <item>option_a</item>
    <item>option_b</item>
</string-array>

现在 - 将这些限制加载到您的应用中:

    RestrictionsManager manager = (RestrictionsManager) getSystemService(this.RESTRICTIONS_SERVICE);
    Bundle restrictions = manager.getApplicationRestrictions();
    loadRestrictions(restrictions);

为了加载它们,我创建了这个 loadRestrictions 示例:

private void loadRestrictions (Bundle bundle) {
    Set<String> keys = bundle.keySet();
    if (keys.isEmpty()) {
        //empty key set here
        //nothing sent via MDM App Config
    } else {
        //we've got keys to process
        for (String k : keys) {
            Object value = bundle.get(k);
            String valueString = "";
            if (value != null) {
                valueString = value.toString();
            }
            switch (k) {
                case "Section1":
                    if (value != null) {
                        loadRestrictions((Bundle) value);
                    }
                    break;
                case "Section2":
                    if (value != null) {
                        loadRestrictions((Bundle) value);
                    }
                    break;
                case "Setting1":
                    //Setting 1
                    // this is an array of choices
                    String optionChoice = "";
                    if(valueString.equals("option_a")) {
                        optionChoice = "Option A Was Chosen";
                    } else if (valueString.equals("option_b")) {
                        optionChoice = "Option B Was Chosen";
                    } else {
                        //we should not ever get here?
                        optionChoice = "ERROR?";
                    }                        
                    break;
                case "Setting2":
                    //Setting 1
                    // value for this key is in valueString
                    String setting2 = (String) valueString;
                    break;
                case "Setting3":
                    //Setting 3
                    // INTEGER value for this key is in value
                    int setting3 = (int) value;
                    break;
                case "Setting4":
                    //Setting 4
                    // INTEGER value for this key is in value
                    int setting4 = (int) value;
                    break;
                case "Setting5":
                    //Setting 5
                    // INTEGER value for this key is in value
                    int setting5 = (int) value;
                    break;
                default:
                    //another odd error occurred here
                    break;
            } //switch
        } //for keys
    }
}//load restrictions

享受!!!

本文链接:https://www.f2er.com/3150565.html

大家都在问