與 AMAPI SDK 整合

Android Management API (AMAPI) SDK 可讓特定應用程式直接與 Android Device Policy (ADP) 通訊。包括支援:

如要將 AMAPI SDK 整合至應用程式,請按照下列步驟操作:

  1. 新增 AMAPI SDK 程式庫
  2. 如果目標 SDK >= 30,請新增 queries 元素

必要條件

  • 確認應用程式的 minSdkVersion 至少設為 API 級別 21。
  • 將最新版 AMAPI SDK 的依附元件加入應用程式。如要瞭解最新可用程式庫的版本,以及如何將程式庫新增至應用程式,請參閱 AMAPI SDK 的發行說明頁面。

新增查詢元素

如果應用程式的目標是 SDK 30 以上版本,則 AndroidManifest.xml 中需要 queries 元素,指定與 ADP 互動。

<queries>
    <package android:name="com.google.android.apps.work.clouddpc" />
</queries>

詳情請參閱「在 Android 上篩選套件瀏覽權限」。

實作 NotificationReceiverService

部分功能需要建立NotificationReceiverService,部分功能則可選擇使用。如要使用這項功能,請定義擴充 NotificationReceiverService 的類別,將其新增為 AndroidManifest.xmlservice,並確保已匯出。


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.
  }
}

AndroidManifest.xml中新增

<service
 android:name = ".MyAppNotificationReceiverService"
 android:exported = "true" />

通常實作 NotificationReceiverService 的類別 ComponentName 需要透過適當的 API 傳遞給我們。詳細資料會因相關功能而異,且每個需要這類文件的功能都會記錄下來。