Pub/Sub 알림을 사용하면 새로 등록된 기기, 기기 보고서, 최근에 실행된 명령어에 관한 알림을 받을 수 있습니다.
Pub/Sub 알림을 설정하려면 Pub/Sub API를 사용 설정하고 주제를 만들어야 합니다. 주제에 게시된 메시지를 받으려면 해당 주제에 대한 구독을 생성해야 합니다. 구독은 주제에 게시된 메시지를 수신하고 처리하는 구독자 애플리케이션과 주제를 연결합니다. 정기 결제를 만든 후에는 Android Device Policy에 주제에 게시할 수 있는 권한을 부여해야 합니다.
구독은 메시지 전달을 위해 push 또는 pull 방법을 사용합니다.
이 두 메커니즘을 통해 알림을 수신하는 방법에 관한 가이드라인과 안내는 Pub/Sub 구독자 가이드에서 확인할 수 있습니다.
메시지 형식
메시지는 PubsubMessage 형식을 사용합니다.
메시지의 attributes 필드에는 키가 notificationType이고 값이 메시지를 트리거한 알림 유형 (예: ENROLLMENT)으로 설정된 속성이 포함됩니다. 메시지의 data 필드에는 업데이트된 리소스의 JSON 표현이 UTF-8 문자열로 인코딩되어 포함됩니다. 알림과 해당 리소스 유형은 다음과 같습니다.
[null,null,["최종 업데이트: 2025-07-26(UTC)"],[[["\u003cp\u003ePub/Sub notifications alert you about device enrollments, reports, and commands issued through the Android Management API.\u003c/p\u003e\n"],["\u003cp\u003eTo set up, you'll need to enable the Pub/Sub API, create a topic and subscription, and grant Android Device Policy publishing rights.\u003c/p\u003e\n"],["\u003cp\u003eEnterprises can be configured to receive specific notification types like enrollment, status reports, and commands by updating their settings.\u003c/p\u003e\n"],["\u003cp\u003eMessages are delivered via Pub/Sub and contain information about the event, including the notification type and resource details.\u003c/p\u003e\n"],["\u003cp\u003eDevice events are often batched into a single Pub/Sub message, and latency between event and notification can vary but is generally within a predictable timeframe.\u003c/p\u003e\n"]]],["To utilize Pub/Sub notifications for Android Management API, first, enable the Pub/Sub API and create a topic, noting its name. Next, create a subscription for the topic. Grant `android-cloud-policy@system.gserviceaccount.com` Pub/Sub Publisher permission. Update your enterprise via `enterprises.patch` to include the topic name and desired notification types (ENROLLMENT, STATUS_REPORT, COMMAND). Finally, use the Pub/Sub API to retrieve notifications, which contain attributes like `notificationType` and a JSON resource in the `data` field. Existing EMM partners need to register their Cloud project.\n"],null,["# Set up Pub/Sub notifications\n\n| **Note:** Existing EMM partners with [programmatically created ESAs](/android/work/play/emm-api/create-enterprise#create_enterprise_service_accounts_programmatically) need to register their preferred Cloud project with Google before setting up Pub/Sub notifications for Android Management API. For more details, see the [Guide for existing EMM partners](/android/management/existing-emms#set_up_pubsub_notifications).\n\nPub/Sub notifications provide a way for you to receive alerts about newly\nenrolled devices, device reports, and recently issued [commands](/android/management/introduction#commands).\n\nTo set up Pub/Sub notifications, you need to enable the Pub/Sub API and create a\n*topic*. To receive messages published to a topic, create a subscription to that\ntopic. The subscription connects the topic to a subscriber application that\nreceives and processes messages published to the topic. After you create a\nsubscription, you need to grant Android Device Policy permission to publish to\nyour topic.\n\n1. Enable the Pub/Sub API for your project\n------------------------------------------\n\nFor instructions on how to enable the Pub/Sub API, see the\n[console quickstart guide](https://cloud.google.com/pubsub/docs/quickstart-console#before-you-begin). Ensure that you select the **same project** that\nthe [Android Management API is enabled for](/android/management/service-account#enable_the_android_management_api).\n\n2. Create a topic\n-----------------\n\nAfter enabling the API, you need to create a topic that Android Device Policy\ncan publish notifications to. There are two ways to create a topic:\n\na. Manually in the [Google Cloud console](https://cloud.google.com/pubsub/docs/quickstart-console#create_a_topic). \n\nb. Using the Pub/Sub API (see [create topic method](https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics/create)).\n\nAfter creating a topic, take note of the topic name.\n\n3. Create a subscription\n------------------------\n\nA subscription captures the stream of messages published to a given topic. There\nare two ways to create a subscription:\n\na. Manually in the [Google Cloud console](https://cloud.google.com/pubsub/docs/quickstart-console#add_a_subscription). \n\nb. Using the Pub/Sub API (see [create subscription method](https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/create)).\n\n4. Grant Android Device Policy the right to publish to your topic\n-----------------------------------------------------------------\n\nYou need to give android-cloud-policy@system.gserviceaccount.com permission to\npublish to your topic. There are two ways to grant publishing rights:\n\na. Manually in the [Google Cloud console](https://cloud.google.com/pubsub/docs/access_control#console).\n\n- Add android-cloud-policy@system.gserviceaccount.com as a member to your topic.\n- Click **Select a role** \\\u003e **Pub/Sub** \\\u003e **Pub/Sub Publisher**.\n\nb. Using the Pub/Sub API (see [Controlling access through the IAM API](https://cloud.google.com/pubsub/docs/access_control#api))\n\n- Add `serviceAccount:android-cloud-policy@system.gserviceaccount.com` to `members`.\n- Set `role` to `roles/pubsub.publisher`.\n\n5. Update enterprise to support notifications\n---------------------------------------------\n\nSkip this step if the notification you want to support is `ENTERPRISE_UPGRADE`,\nwhich is always supported.\n\nTo connect notifications about an enterprise to the topic you created, call\n[`enterprises.patch`](/android/management/reference/rest/v1/enterprises/patch)\nand specify the following parameters:\n\n- `pubsubTopic`: The name of your pub/sub topic in the form `projects/{project}/topics/{topic}`.\n- `enabledNotificationTypes`: Include all the notification [types](/android/management/reference/rest/v1/enterprises#NotificationType) you want to receive.\n\n6. Use the Pub/Sub API to get notifications\n-------------------------------------------\n\nA subscription can use either the push or pull mechanism for message delivery.\nGuidelines and directions on how to receive notifications through both of these\nmechanisms are available in the [Pub/Sub Subscriber Guide](https://cloud.google.com/pubsub/docs/subscriber).\n\nMessage format\n--------------\n\nMessages take the form of a [PubsubMessage](https://cloud.google.com/pubsub/docs/reference/rest/v1/PubsubMessage).\nThe `attributes` field of the message contains an attribute with key\n`notificationType` and value set to the notification type that triggered the\nmessage (e.g. `ENROLLMENT`). The `data` field of the message contains the JSON\nrepresentation of the resource that was updated, encoded as a UTF-8 string. The\nnotifications and their corresponding resource types are as follows:\n\n- `COMMAND` notifications use the resource type [Operation](/android/management/reference/rest/v1/enterprises.devices.operations#resource-operation).\n- `USAGE_LOGS` notifications use the resource type [UsageLogEvent](/android/management/reference/rest/v1/BatchUsageLogEvents#usagelogevent).\n- `ENROLLMENT` and `STATUS_REPORT` notifications use the resource type [Device](/android/management/reference/rest/v1/enterprises.devices#resource-device).\n- `ENTERPRISE_UPGRADE` notifications use the resource type [EnterpriseUpgradeEvent](/android/management/reference/rest/v1/EnterpriseUpgradeEvent).\n\nWhen setting the `pubsubTopic` on an Enterprise, an initial message will be\npublished with `notificationType` set to `test`. This message is sent to verify\nAndroid Device Policy has the publish permission on the topic and should be\nignored.\n| **Note:** When using the Pub/Sub REST API, the `data` field is encoded as a base64 string. To get the resource JSON, first perform base64 decoding on the contents of `data`, then interpret the resulting bytes as a UTF-8 string.\n\nExpected latency\n----------------\n\nEnterprise upgrade events are expected to be sent immediately.\n\nLocal device events that occur in quick succession are batched and reported in a\nsingle Pub/Sub message to EMMs.\n\n| Event type | Expected latency between on-device event and corresponding EMM notification^[1](#fn1)^ |\n|--------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------|\n| High priority [keyed app states](/android/management/app-feedback) | Immediate, at most one report per minute |\n| Standard priority [keyed app states](/android/management/app-feedback) | Within one minute |\n| Application-related events during provisioning, for apps with install states defined by the IT admin^[2](#fn2)^ | Within one minute on top of other related provisioning events |\n| Application-related events after provisioning, for apps with install states defined by the IT admin. | Within 5 minutes |\n| Application-related events both during and after provisioning, for apps with install states defined by the employee^[3](#fn3)^ | Within 60 minutes |\n| Other on-device app events | Within 60 minutes |\n\n*** ** * ** ***\n\n1. Best effort targets based on controlled circumstances. Actual latency may\n vary according to a variety of device and environmental factors. [↩](#fnref1)\n\n2. [`InstallType`](/android/management/reference/rest/v1/enterprises.policies#installtype) of apps enforced in the policy: `FORCE_INSTALLED`,\n `BLOCKED`, `REQUIRED_FOR_SETUP`, `PREINSTALLED` and `KIOSK`. [↩](#fnref2)\n\n3. [`InstallType`](/android/management/reference/rest/v1/enterprises.policies#installtype) of available apps: `AVAILABLE`,\n `INSTALL_TYPE_UNSPECIFIED`. [↩](#fnref3)"]]