企业应用程序的托管配置(Android Management API)



我正在使用Android管理。API提供平板电脑设备。我为这些应用程序中的每一个都制定了策略,在这些策略中,我为"terminal"设置了managedConfiguration,我打算将此字符串值用作我设置的"terminary"的标识符。以下是应用程序策略:

"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>

调用enterprises.applications.get显示托管配置设置已被识别:

{
"key": "terminal",
"type": "STRING",
"title": "@strings/terminal_title"
} 

在我的应用程序代码中(以下两个片段都在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"?

我使用了TestDPC应用程序,并能够测试我的托管配置设置。我不确定,但我相信我的应用程序错误是由于启用了缩小和资源缩减。我不知道如果没有TestDPC,任何人如何生存。这大大加快了开发周期。

需要补充的是:TestDPC通过adb在工作提供的三星平板电脑上安装得很好(我记不清确切的型号了,但它基本上是全新的(。然而,我尝试了另一个SM-T500,在运行adb时出现了错误。我能让TestDPC配置工作的唯一方法是这个方法,所以我在工厂重置并使用标识符afw#TestDPC。

我还遵循了本指南,更具体地说是AppRestrictionsSchema上的区域。我更新了代码以使用resolveRestrictions函数,并将广播接收器处理放在各种生命周期函数中。同样,这很顺利,所以我会按照这个格式为任何想要设置它的人服务。

我已经部署到一个设备上,托管配置运行良好,所以希望这能帮助其他人走上同样的道路。

为应用程序设置托管配置时,需要做的第一件事就是定义托管配置。

一旦定义了托管配置,您就需要在应用程序启动或恢复时检查托管配置是什么,并监听系统意图,以了解在应用程序运行时配置是否发生了更改,因为当托管配置发生更改时,系统不会自动通知您的应用程序。

最后,您需要听取托管配置的更改。有关如何设置的更多信息,您可以参考本文档。

以下是onCreate:中添加的示例代码

val config = this.getSystemService(Context.RESTRICTIONS_SERVICE) as RestrictionsManager
val identifier = "welcome_msg"
val appRestrictions = config.applicationRestrictions
if (appRestrictions.containsKey(identifier)) {
val myText  = findViewById<TextView>(R.id.txtMessage)
myText.text = appRestrictions.getString(identifier)
}
// listener for changes while app is active
val restrictionsReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
// Get the current configuration bundle
val appRestrictions = config.applicationRestrictions
if (appRestrictions.containsKey(identifier)) {
val myText  = findViewById<TextView>(R.id.txtMessage)
myText.text = appRestrictions.getString(identifier)
}
}
}
val restrictionsFilter = IntentFilter(Intent.ACTION_APPLICATION_RESTRICTIONS_CHANGED)
registerReceiver(restrictionsReceiver, restrictionsFilter)

这是restriction.xml:

<?xml version="1.0" encoding="utf-8"?>
<restrictions xmlns:android="http://schemas.android.com/apk/res/android">
<restriction
android:key="welcome_msg"
android:title="Welcome Message"
android:restrictionType="string"
android:defaultValue="" />
</restrictions>

最新更新