简体   繁体   English

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

[英]Managed Configurations for an enterprise app (Android Management API)

I'm using the Android Mgmt.我正在使用 Android Mgmt。 API to provision tablet devices.用于配置平板电脑设备的 API。 I have policies for each of these apps, and within the policies, I set a managedConfiguration for 'terminal,' which I was intending to be able to use this string value as the identifier for which 'terminal' I have setup.我为这些应用程序中的每一个制定了策略,在策略中,我为“终端”设置了一个 managedConfiguration,我打算能够使用这个字符串值作为我设置的“终端”的标识符。 Here is the application policy:以下是申请政策:

  "applications": [
    {
      "packageName": "packageName",
      "installType": "KIOSK",
      "defaultPermissionPolicy": "GRANT",
      "managedConfiguration": {
        "terminal": "2208"
      }
    }, 

My res > xml > app_restrictions.xml:我的资源 > 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>

A call to enterprises.applications.get shows that the managed config settings are recognized:对 enterprise.applications.get 的调用显示托管配置设置已被识别:

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

Inside my app code(both following snippets are inside onCreate):在我的应用程序代码中(以下两个片段都在 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) 

And here's the listener bit.这是听众位。 Note, I will move this logic outside of onCreate.请注意,我会将这个逻辑移到 onCreate 之外。 For now, with my main app, I just wanted to test if each app would receive the MC 'terminal' value that I setup in each policy.现在,使用我的主应用程序,我只想测试每个应用程序是否会收到我在每个策略中设置的 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()
                }
            }
        }
    }

My app isn't receiving the value.我的应用没有收到价值。 Am I missing something with this?我错过了什么吗? Why isn't my identifier.id (a string field) receiving '2208'?为什么我的 identifier.id(字符串字段)没有收到“2208”?

I used the TestDPC app and was able to test my managed config settings.我使用了 TestDPC 应用程序并且能够测试我的托管配置设置。 I don't know for certain, but I believe that my app errors were due to minification and resource shrinking being enabled.我不确定,但我相信我的应用程序错误是由于启用了缩小和资源收缩。 I don't know how anyone could survive without having TestDPC in place.如果没有 TestDPC,我不知道任何人如何生存。 This sped up the development cycle significantly.这显着加快了开发周期。

Something to add: TestDPC installed fine via adb on a Samsung Tablet provided by work (I can't remember the exact model, but it was essentially brand new).补充一点:TestDPC 通过 adb 在工作提供的三星平板电脑上安装得很好(我不记得确切的型号,但它基本上是全新的)。 However, I tried another, SM-T500, and there was an error when running adb.但是,我又试了一个,SM-T500,运行adb时出现错误。 The only way I could get the TestDPC provisioning to work was this method , so I factory reset and used the identifier afw#testdpc.我可以让 TestDPC 配置工作的唯一方法是这种方法,所以我恢复出厂设置并使用标识符 afw#testdpc。

I also ended up following this guide , more specifically the area on AppRestrictionsSchema .我也最终遵循了本指南,更具体地说是AppRestrictionsSchema上的区域。 I updated my code to use a resolveRestrictions function, as well as putting the broadcast receiver handling in the various lifecycle functions.我更新了我的代码以使用 resolveRestrictions 函数,并将广播接收器处理放在各种生命周期函数中。 Again, this worked swimmingly, so I'd follow that format for anyone wanting to set this up.同样,这工作得很好,所以我会为任何想要设置它的人遵循这种格式。

I've deployed to a device and the managed configurations are working fine, so hope this can help someone else going down the same path.我已经部署到设备并且托管配置工作正常,所以希望这可以帮助其他人沿着相同的道路前进。

First thing you need to do when setting up managed configurations for your app is to define the managed configurations .为您的应用程序设置托管配置时,您需要做的第一件事是定义托管配置

Once the managed configs are defined, you then need to check what the managed configurations are when your app starts or resumes, and listen for a system intent to find out if the configurations change while your app is running because it does not automatically notify your app when a change in managed configs are made.一旦定义了托管配置,您就需要在您的应用程序启动或恢复时检查托管配置是什么,并侦听系统意图以查明在您的应用程序运行时配置是否发生变化,因为它不会自动通知您的应用程序当托管配置发生更改时。

Lastly, you need to listen to managed configurations changes .最后,您需要监听托管配置更改 For more information about how to set this up, you may refer to this documentation .有关如何设置的更多信息,您可以参考此文档

Here's a sample code added inside onCreate:这是在 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)

Here's the restriction.xml:这是限制.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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android 管理 API - 调用者无权管理企业 - Android Management API - Caller is not authorized to manage enterprise Android托管配置提供商 - Android managed configurations provider IT管​​理员如何配置具有托管配置的Android应用程序 - How can IT admins configure an Android app with managed configurations 在通过 android 管理 api 控制的完全托管设备中启用内部应用程序共享 - Enable Internal app sharing in fully managed device controlled through android management api 是否有在Android中实施企业托管应用程序配置的标准方法? - Is there a standard way to implement enterprise managed app configuration in Android? 如何在可能没有托管配置提供程序的应用程序中使用托管配置? - How to use Managed Configurations in an app that may not have a Managed Configurations Provider? Android管理api EMM中来自企业的域和域用户 - Domain and domain user from the enterprise in Android management api EMM 使用Android管理API创建企业时如何获取enterpriseToken? - How to get the enterpriseToken when creating an enterprise with the Android Management API? 在活动设备上使用 Android 管理 API 的完全托管注册 - Fully managed enrollment with Android Management API on active device 后台服务未在 Android 管理 API 中的完全托管设备上运行 - Background service not running on a fully managed device in Android Management API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM