Tích hợp với SDK AMAPI
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
SDK Android Management API (AMAPI) cho phép các ứng dụng cụ thể giao tiếp trực tiếp với Android Device Policy (ADP). Thư viện này hỗ trợ:
Bạn phải thực hiện các bước sau để tích hợp AMAPI SDK với ứng dụng của mình:
- Thêm thư viện AMAPI SDK.
- Thêm phần tử truy vấn, nếu SDK mục tiêu >= 30.
Điều kiện tiên quyết
- Xác minh để đảm bảo rằng
minSdkVersion
của ứng dụng được đặt thành ít nhất là API cấp 21.
- Thêm các phần phụ thuộc cho phiên bản mới nhất của AMAPI SDK vào ứng dụng của bạn. Bạn có thể xem phiên bản của thư viện mới nhất hiện có và cách thêm thư viện đó vào ứng dụng của mình trên trang ghi chú phát hành của AMAPI SDK.
Thêm phần tử truy vấn
Nếu ứng dụng của bạn nhắm đến SDK 30 trở lên, thì cần có phần tử truy vấn trong AndroidManifest.xml
để chỉ định rằng ứng dụng sẽ tương tác với ADP.
<queries>
<package android:name="com.google.android.apps.work.clouddpc" />
</queries>
Hãy xem bài viết Lọc chế độ hiển thị gói trên Android để biết thêm thông tin.
Triển khai NotificationReceiverService
Một số tính năng yêu cầu bạn tạo NotificationReceiverService
, còn một số tính năng cho phép bạn sử dụng tuỳ chọn này. Để sử dụng, hãy xác định một lớp mở rộng NotificationReceiverService
, thêm lớp đó dưới dạng service
vào AndroidManifest.xml
và đảm bảo lớp đó được xuất.
import com.google.android.managementapi.notification.NotificationReceiverService;
...
public final class MyAppNotificationReceiverService extends NotificationReceiverService {
@Override
protected void setupInjection() {
// This method can be optionally used to inject dependencies at the
// beginning of the service lifecycle.
}
}
Trong AndroidManifest.xml
, hãy thêm
<service
android:name = ".MyAppNotificationReceiverService"
android:exported = "true" />
Thông thường, ComponentName
của lớp triển khai NotificationReceiverService
cần được truyền cho chúng tôi thông qua một API phù hợp.
Thông tin chi tiết sẽ khác nhau tuỳ thuộc vào tính năng được đề cập và mỗi tính năng cần có thông tin này đều có tài liệu.
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-08-28 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-08-28 UTC."],[],[],null,["The [Android Management API (AMAPI) SDK](https://maven.google.com/web/index.html#com.google.android.libraries.enterprise.amapi) enables specific apps to\ncommunicate directly with Android Device Policy (ADP). It includes support for:\n\n- [Local execution of Commands](/android/management/sdk-local-commands)\n- [Migrate devices managed with a custom DPC to AMAPI](/android/management/dpc-migration)\n- [Device Trust from Android Enterprise](/android/management/device-trust-api)\n- New device enrollment flow that also supports adding managed Google Accounts\n- [Manage custom apps with AMAPI](/android/management/manage-custom-apps)\n\nThe following steps must be taken to integrate the AMAPI SDK with your\napplication:\n\n1. [Add the AMAPI SDK library](/android/management/sdk-release-notes#declare_dependencies).\n2. [Add the queries element](#add_queries), if target SDK \\\u003e= 30.\n\n| **Note:** If you are developing an extension app, you will also need to provision the device with an [extensibility policy](/android/management/sdk-local-commands#policy).\n\nPrerequisites\n\n- Verify that your app's `minSdkVersion` is set to at least API level 21.\n- Add the dependencies for the latest version of the AMAPI SDK to your application. You can find the version of the latest available library, and how to add it to your application, in the [AMAPI SDK's release notes](/android/management/sdk-release-notes) page.\n\nAdd queries element\n\nIf your app targets SDK 30 or later, then queries element is needed in the\n`AndroidManifest.xml` to specify that it will interact with ADP. \n\n \u003cqueries\u003e\n \u003cpackage android:name=\"com.google.android.apps.work.clouddpc\" /\u003e\n \u003c/queries\u003e\n\nSee [Package visibility filtering on Android](https://developer.android.com/training/package-visibility) for more information.\n\nImplement a NotificationReceiverService\n\nSome features require creating a\n[`NotificationReceiverService`](/android/management/reference/amapi/com/google/android/managementapi/notification/NotificationReceiverService), and some features\nmake optional use of it. To use it, define a class extending\n`NotificationReceiverService`, add it as a `service` to your\n`AndroidManifest.xml`, and make sure it is exported. \n\n\n import com.google.android.managementapi.notification.NotificationReceiverService;\n\n ...\n\n public final class MyAppNotificationReceiverService extends NotificationReceiverService {\n\n @Override\n protected void setupInjection() {\n // This method can be optionally used to inject dependencies at the\n // beginning of the service lifecycle.\n }\n }\n\nIn your `AndroidManifest.xml`, add \n\n \u003cservice\n android:name = \".MyAppNotificationReceiverService\"\n android:exported = \"true\" /\u003e\n\nTypically the `ComponentName` of your class which implements\n`NotificationReceiverService` needs to be passed to us through a suitable API.\nThe details vary depending on the feature in question, and each feature which\nneeds this documents it."]]