【发布时间】:2021-01-05 17:21:33
【问题描述】:
我正在使用 Android Mgmt。用于配置平板设备的 API。我对这些应用程序中的每一个都有策略,并且在策略中,我为“终端”设置了一个 managedConfiguration,我打算使用这个字符串值作为我设置的“终端”的标识符。以下是申请政策:
"applications": [
{
"packageName": "packageName",
"installType": "KIOSK",
"defaultPermissionPolicy": "GRANT",
"managedConfiguration": {
"terminal": "2208"
}
},
我的资源 > xml > app_restrictions.xml:
<?xml version="1.0" encoding="utf-8"?>
<restrictions xmlns:android="http://schemas.android.com/apk/res/android">
<restriction
android:key="facility"
android:title="@strings/facility_title"
android:restrictionType="string" />
<restriction
android:key="terminal"
android:title="@strings/terminal_title"
android:restrictionType="string" />
</restrictions>
对 enterprise.applications.get 的调用表明托管配置设置已被识别:
{
"key": "terminal",
"type": "STRING",
"title": "@strings/terminal_title"
}
在我的应用代码中(以下两个 sn-ps 都在 onCreate 中):
val config = this.getSystemService(Context.RESTRICTIONS_SERVICE) as RestrictionsManager
val identifier = TerminalIdentifier("")
val appRestrictions = config.applicationRestrictions
if (appRestrictions.containsKey("terminal")) {
identifier.id = appRestrictions.getString("terminal").toString()
}
// listener for changes while app is active
val restrictionsReceiver = this.setupRestrictionsReceiver(identifier, appRestrictions)
val restrictionsFilter = IntentFilter(Intent.ACTION_APPLICATION_RESTRICTIONS_CHANGED)
registerReceiver(restrictionsReceiver, restrictionsFilter)
这是监听器位。请注意,我将把这个逻辑移到 onCreate 之外。目前,对于我的主应用程序,我只想测试每个应用程序是否会收到我在每个策略中设置的 MC '终端' 值。
private fun setupRestrictionsReceiver(identifier: IdentifierService, restrictions : Bundle) : BroadcastReceiver {
return object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (restrictions.containsKey("terminal")) {
identifier.id = restrictions.getString("terminal").toString()
}
}
}
}
我的应用没有收到价值。我错过了什么吗?为什么我的 identifier.id(字符串字段)没有收到 '2208'?
【问题讨论】:
-
您是否在 xml 定义文件中定义了应用程序支持的限制,如文档中所述? developer.android.com/work/…
-
@petarov 是的,我制作了 res > xml > app_restrictions.xml,并且在“应用程序”下添加了我的清单,我直接从文档中复制了该部分。就像我在帖子中所说的那样,enterprise.applications.get 似乎注意到了这个限制,但不确定应用程序中发生了什么。感谢你们对我的帮助。如果有帮助,我会用我的 app_restrictions.xml 更新问题。
-
唯一的其他原因似乎是设备不受管理,即应用程序不是受管理配置文件的一部分。请参阅此处了解更多信息 - stackoverflow.com/a/41941367/10364676
-
@petarov 谢谢。我已经看过 testdpc 应用程序并且现在正在使用它。万一其他人读到这篇文章并正在做一个完全托管的设备,我遵循这部分:link。我所做的是通过usb将我的android设备插入我的电脑,然后在android studio中我打开了一个终端,从'platform-tools'目录运行adb命令。然后在设备上,转到 testdpc 应用程序。可以从那里为您的应用设置托管配置。调试我的帖子问题后会跟进。
标签: android android-management-api