【问题标题】:Enterprise Android App Config - Application Restrictions - Not working as expected企业 Android 应用程序配置 - 应用程序限制 - 未按预期工作
【发布时间】:2020-03-03 04:32:35
【问题描述】:

真的可以使用一些指导来调试/解决我遇到的这个问题。

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

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

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

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

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

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

我找不到任何好的资源来解决这部分过程的问题。

以前做过这个的人有什么想法吗?

【问题讨论】:

    标签: android enterprise mdm android-restrictions


    【解决方案1】:

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

    这是我将 App Config 设置添加到您的应用程序中的指南,以便任何 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

    字符串.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
    

    享受!!!

    【讨论】:

      【解决方案2】:

      当您使用此方法时:getManifestRestriction 限制管理器获取 XML 应用程序限制,但是当您使用此方法时:getApplicationRestrictions 应用程序从您的 EMM/MDM 读取限制,此外,您必须配置广播接收器以侦听任何改变你的政策。

      还有一件事:就我而言,我必须创建一个包含所有应用限制的共享首选项,以保存当前设置并避免设备在重启后擦除它们。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-08-24
        • 2017-06-03
        • 2018-03-10
        • 1970-01-01
        相关资源
        最近更新 更多