2

According to the restriction entry types, for defining a list of objects we should use the bundle_array type, and an example follows:

<?xml version="1.0" encoding="utf-8"?>
<restrictions xmlns:android="http://schemas.android.com/apk/res/android" >

  <restriction
    android:key="vpn_configuration_list"
    android:restrictionType="bundle_array">
    <restriction
      android:key="vpn_configuration"
      android:restrictionType="bundle">
      <restriction
        android:key="vpn_server"
        android:restrictionType="string"/>
      <restriction
        android:key="vpn_username"
        android:restrictionType="string"/>
      <restriction
        android:key="vpn_password"
        android:restrictionType="string"/>
    </restriction>
  </restriction>

</restrictions>

In code that would be similar to a List<VpnConfiguration>, and VpnConfiguration would be a pojo with the three fields vpn_server, vpn_username, and vpn_password.

So far so good, now imagine that a simpler data structure is needed, like a String[]. According to Test DPC this should be possible, because there's an option to insert an array of strings:

enter image description here

Once you select it, then you are prompted to enter the list of values. However, the documentation does not have a string_array type, it has only the bundle_array.

With bundle_array you can define a List<String> instead of String[], but that is overkill:

<restriction
    android:key="mylist"
    android:restrictionType="bundle_array">

    <restriction
        android:key="item"
        android:restrictionType="bundle">

        <restriction
            android:key="name"
            android:restrictionType="string" />

    </restriction>
</restriction>

So, is there a simpler way one can define a string array?

4

2 回答 2

2

String[]仅针对限制类型返回值类型,multi-selectEMM 会返回一组条目,这些条目是从您在 中定义的条目中选择的android:entryValues

如果您想允许企业管理员输入一个自由格式的字符串列表,那么您确实应该定义一个bundle_array包含string限制的。

编辑:请注意,这bundle_array仅适用于 Android 6.0+,并且在 Android 5.0/5.1 上没有传递自由格式字符串列表的标准方法。您可以想象在 a 中传递 JSON,string但您需要就该 JSON 的格式与 EMM 达成一致,因此它不会自动适用于所有 EMM。

于 2017-08-11T09:14:38.690 回答
-1

好的,看起来可以使用与定义字符串相同的方式定义字符串数组:

   <restriction
        android:key="my_array"
        android:restrictionType="string"
        android:title="My Array">

然后在接收部分,您必须确保将数据作为字符串数组读取:

String[] array = restrictions.getStringArray("my_array");

缺点是在后端(EMM 管理)没有任何线索表明上述限制应该被视为字符串数组而不是字符串。

我通过测试发现了这一点,仍然不确定这是否是正确的方法......

于 2017-08-11T09:02:15.097 回答