[null,null,["最后更新时间 (UTC):2025-07-26。"],[],[],null,["# Send app feedback to EMMs\n\nEnterprise mobility management (EMM) providers offer solutions for organizations\nto manage Android devices and the apps installed on them. These solutions are\ntypically available as web consoles, called *EMM consoles*. Using an EMM\nconsole, IT admins perform device and app management tasks on behalf of their\norganization.\n\nApps targeting enterprise organizations can send feedback to EMMs in the form of\nkeyed app states. APIs are available for EMMs to retrieve keyed app state data,\nwhich they can then display in their EMM console. This communication channel\nallows IT admins to receive feedback about the status of the apps installed on\nthe devices they manage.\n\nFor example, an email client app could use keyed app states to confirm that an\naccount was successfully configured, report when sync errors occur, or send any\nother status updates the app developer thinks is appropriate.\n\n### Components of a keyed app state\n\nA keyed app state is comprised of the following:\n\n- **Key:** Unique identifier for the app state. Maximum 100 characters.\n- **Message:** Optional message describing the app state. Maximum 1000 characters. Note: Typically messages should be significantly shorter than this.\n- **Data:** Optional machine-readable value intended for EMMs to allow IT admins to set up alerts or filters based on the value. For example, an IT admin could set up an alert if the data field `battery_percentage \u003c 10`. Maximum 1000 characters.\n- **Severity:** The severity of the app state. Allowable values are [`SEVERITY_ERROR`](/reference/androidx/enterprise/feedback/KeyedAppState#SEVERITY_ERROR) and [`SEVERITY_INFO`](/reference/androidx/enterprise/feedback/KeyedAppState#SEVERITY_INFO) (default). Only set severity to [`SEVERITY_ERROR`](/reference/androidx/enterprise/feedback/KeyedAppState#SEVERITY_ERROR) for genuine error conditions that an organization needs to take action to fix.\n- **Timestamp:**When a keyed app state is set, it's automatically sent with a timestamp in milliseconds since epoch.\n\nSend managed configurations feedback\n------------------------------------\n\nIf your app supports [managed configurations](/work/managed-configurations),\nsending keyed app states is recommended as a way to update IT admins on the\nstatus of the configurations they set. The following example workflow describes\none way to do this.\n\n1. IT admins use their EMM console to set and send managed configurations for an app installed on a [fully managed device](https://developers.google.com/android/work/terminology#fully_managed_device) or inside a [work profile](https://developers.google.com/android/work/terminology#work_profile). For example:\n - Volume: '50%'\n - Currency: 'USDD'\n2. The app attempts to apply the configurations. The volume is set successfully to 50%, but the currency code is invalid and can't be applied.\n3. Based on the status of each configuration, the app sets a keyed app state. Each keyed app state contains a unique key and a message with details of the state. We recommend matching the managed configurations key where possible. For example:\n\n | Key | Message | Severity | Timestamp |\n |------------|--------------------------------|------------------------------------------------------------------------------------------|--------------|\n | `volume` | Set to 50% | [`SEVERITY_INFO`](/reference/androidx/enterprise/feedback/KeyedAppState#SEVERITY_INFO) | `1554461130` |\n | `currency` | Currency 'USDD' not recognized | [`SEVERITY_ERROR`](/reference/androidx/enterprise/feedback/KeyedAppState#SEVERITY_ERROR) | `1554461130` |\n\n4. The EMM provider retrieves the keyed app states set by the app and displays them in its EMM console. For example:\n\n | Configuration | Status | Action required | Time |\n |---------------|----------------------------------------|-----------------|----------------------------|\n | Volume | Set to 50% | No | April 5, 2019; 10:45:30 AM |\n | Currency | ERROR: Currency 'USDD' not recognized. | Yes | April 5, 2019; 10:45:30 AM |\n\n The EMM provider should also explicitly flag any received states with\n [`SEVERITY_ERROR`](/reference/androidx/enterprise/feedback/KeyedAppState#SEVERITY_ERROR)\n to the IT admin. IT admins can view the information in their EMM console and\n take action to rectify any errors in the configurations they set.\n\n### Report resolved errors\n\nAfter an error is resolved, immediately send a follow-up app state to\nprevent EMMs from displaying the error message indefinitely. This follow-up\nstate should include:\n\n- The same [key](/reference/androidx/enterprise/feedback/KeyedAppState#getKey()) as the initial error message.\n- A severity of [`SEVERITY_INFO`](/reference/androidx/enterprise/feedback/KeyedAppState#SEVERITY_INFO), which indicates that the state isn't in an error condition and doesn't require the organization to take any further action.\n\nAdd support for keyed app states to your app\n--------------------------------------------\n\nThe steps below describe how to integrate keyed app states in your app.\n\n### Step 1: Add Google's Maven repository to your `settings.gradle` file\n\nAdd Google's Maven repository as a repository location in your project's [`settings.gradle`](/studio/build#settings-file)\nfile, as shown below: \n\n```\ndependencyResolutionManagement {\n repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)\n repositories {\n google()\n }\n}\n```\n\n### Step 2: Add the enterprise feedback library to your module-level `build.gradle` file\n\nAdd the following dependency to your module-level [`build.gradle`](/studio/build#module-level)\nfile: \n\n```\ndependencies {\n implementation 'androidx.enterprise:enterprise-feedback:1.0.0'\n}\n```\n\n### Step 3: Get an instance of `KeyedAppStatesReporter`\n\nIn your `onCreate()` method, get and store an instance of\n[`KeyedAppStatesReporter`](/reference/androidx/enterprise/feedback/KeyedAppStatesReporter).\nThis enables a communication channel between your app and EMM providers. \n\n### Kotlin\n\n```kotlin\nval reporter = KeyedAppStatesReporter.create(context)\n```\n\n### Java\n\n```java\nKeyedAppStatesReporter reporter = KeyedAppStatesReporter.create(context);\n```\n\n### Step 4: Create a collection of keyed app states\n\nFollow the best practices outlined below when creating keyed app states:\n\n- Never include personally identifiable information (PII) in a state---keyed apps states aren't suitable for sensitive data.\n- Keep keyed app states within the limits defined in [`MAX_KEY_LENGTH`](/reference/androidx/enterprise/feedback/KeyedAppState#MAX_KEY_LENGTH), [`MAX_MESSAGE_LENGTH`](/reference/androidx/enterprise/feedback/KeyedAppState#MAX_MESSAGE_LENGTH), and [`MAX_DATA_LENGTH`](/reference/androidx/enterprise/feedback/KeyedAppState#MAX_DATA_LENGTH).\n- A single `setStates` or `setStatesImmediate` call is limited to 300 KB total (approximately 1/3 of the total that can be stored per day). Exceeding this will result in undefined behavior.\n- Only set the severity of a state to [`SEVERITY_ERROR`](/reference/androidx/enterprise/feedback/KeyedAppState#SEVERITY_ERROR) if a condition exists that an organization needs to take action to fix.\n- When sending an app state containing errors, ensure that you also send a follow-up state when the errors are resolved so the EMM can stop flagging the errors in their console.\n- For the follow-up state, use the same [key](/reference/androidx/enterprise/feedback/KeyedAppState#getKey()) as the initial state that returned the error and set severity to [`SEVERITY_INFO`](/reference/androidx/enterprise/feedback/KeyedAppState#SEVERITY_INFO).\n\nThe snippet below creates a collection of keyed app states: \n\n### Kotlin\n\n```kotlin\n val states = hashSetOf(KeyedAppState.builder()\n .setKey(\"key\")\n .setSeverity(KeyedAppState.SEVERITY_INFO)\n .setMessage(\"message\")\n .setData(\"data\")\n .build())\n \n```\n\n### Java\n\n```java\n Collection states = new HashSet\u003c\u003e();\n states.add(KeyedAppState.builder()\n .setKey(\"key\")\n .setSeverity(KeyedAppState.SEVERITY_INFO)\n .setMessage(\"message\")\n .setData(\"data\")\n .build());\n \n```\n\n### Step 5: Set the keyed app states\n\n| **Note:** You can set up to 500 unique keys per day for your app. There's no limit to the number of states you can set for each unique key.\n\nThe [`setStates()`](/reference/androidx/enterprise/feedback/KeyedAppStatesReporter#setStates(java.util.Collection\u003candroidx.enterprise.feedback.KeyedAppState\u003e))\nmethod immediately sends keyed app states to the Play Store app (package name:\n`com.android.vending`) if it's installed on the device, as well as any admins of the\ndevice or work profile. \n\n### Kotlin\n\n```kotlin\nkeyedAppStatesReporter.setStates(states)\n```\n\n### Java\n\n```java\nkeyedAppStatesReporter.setStates(states);\n```\n\nTest keyed app states\n---------------------\n\nFor detailed test instructions, see [Test app feedback](/work/app-feedback/testing)."]]