EnvironmentClient

interface EnvironmentClient


用戶端可存取環境相關 API。

請使用 EnvironmentClientFactory 建立例項。

摘要

公開函式

suspend Environment

傳回 Environment

ListenableFuture<Environment>

傳回 Environment

suspend PrepareEnvironmentResponse
@RequiresApi(value = 28)
prepareEnvironment(
    request: PrepareEnvironmentRequest,
    notificationServiceComponentName: ComponentName?
)

準備裝置環境。

ListenableFuture<PrepareEnvironmentResponse>
@RequiresApi(value = 28)
prepareEnvironmentAsync(
    request: PrepareEnvironmentRequest,
    notificationServiceComponentName: ComponentName?
)

準備裝置環境。

公開函式

getEnvironment

@RequiresApi(value = 28)
suspend fun getEnvironment(request: GetEnvironmentRequest): Environment

傳回 Environment。這有助於呼叫端瞭解環境是否就緒。

擲回
java.lang.SecurityException

如果呼叫端沒有呼叫此 API 的權限。

com.google.android.managementapi.common.exceptions.ApiLevelException

如果裝置 API 級別低於 28。

com.google.android.managementapi.common.exceptions.InvalidArgumentException

如果要求的角色無效。

com.google.android.managementapi.common.exceptions.InternalException

如果通話因內部錯誤而失敗。

getEnvironmentAsync

@RequiresApi(value = 28)
fun getEnvironmentAsync(request: GetEnvironmentRequest): ListenableFuture<Environment>

傳回 Environment。這有助於呼叫端瞭解環境是否就緒。

傳回
ListenableFuture<Environment>

包裝結果的 ListenableFuture。可能的原因包括:

  • 成功的未來包裝 Environment (在成功的情況下)。

  • 如果呼叫端未獲准呼叫此 API,則會包裝 SecurityException 的失敗未來。

  • 如果裝置 API 級別低於 28,則會發生 ApiLevelException 包裝失敗的未來事件。

  • 如果要求的角色無效,則會發生 InvalidArgumentException 包裝失敗的未來事件。

  • 如果呼叫因內部錯誤而失敗,則包裝 InternalException 的失敗 Future。

prepareEnvironment

@RequiresApi(value = 28)
suspend fun prepareEnvironment(
    request: PrepareEnvironmentRequest,
    notificationServiceComponentName: ComponentName?
): PrepareEnvironmentResponse

準備裝置環境。

提示使用者安裝必要的 Android Device Policy 應用程式。如果使用者接受提示,系統就會繼續安裝。安裝成功後,系統會執行相關作業,確保 Android Device Policy 應用程式已就緒。

參數
notificationServiceComponentName: ComponentName?

擴充 NotificationReceiverService 的服務的 ComponentName。如果提供,則必須是屬於呼叫應用程式的有效元件,並在資訊清單中匯出。如要接收環境準備事件的通知,您必須:

  1. 在應用程式中實作 EnvironmentListener 介面。

  2. 提供如何處理收到的事件的實作方式。

  3. 擴充 NotificationReceiverService,並提供 EnvironmentListener 例項。

  4. 將擴充的 NotificationReceiverService 類別新增至 AndroidManifest.xml,並確認已匯出。

例如:

class MyEnvironmentListener : EnvironmentListener {
override fun onEnvironmentEvent(event: EnvironmentEvent) {
// Handle the environment event.
}
}

class MyNotificationReceiverService : NotificationReceiverService() {
override fun getPrepareEnvironmentListener(): EnvironmentListener? {
return MyEnvironmentListener()
}
}
傳回
PrepareEnvironmentResponse

PrepareEnvironmentResponse,其中包含環境準備作業的最終狀態詳細資料。

擲回
com.google.android.managementapi.common.exceptions.InvalidArgumentException

如果:

  • [notificationServiceComponentName] 不是屬於呼叫應用程式的有效元件,或是未在資訊清單中匯出。
  • 要求的角色無效。
com.google.android.managementapi.common.exceptions.ApiLevelException

如果裝置 API 級別低於 28。

java.lang.SecurityException

如果呼叫端沒有呼叫此 API 的權限。

com.google.android.managementapi.environment.exception.GooglePlayServicesAppNotUpdatedException 如果 Google Play 服務不是最新版本。

com.google.android.managementapi.environment.exception.AndroidDevicePolicyInstallOrUpdateUnrecoverableException 如果 Android 裝置政策無法安裝或更新,且無法復原錯誤。

com.google.android.managementapi.environment.exception.AndroidDevicePolicyInstallOrUpdateRecoverableException 如果 Android 裝置政策應用程式無法安裝或更新,且錯誤可復原 (例如因暫時性網路問題導致要求失敗),則可重試要求。

com.google.android.managementapi.environment.exception.AndroidDevicePolicyInstallConsentDeclinedException 如果使用者拒絕安裝 Android Device Policy 應用程式。

com.google.android.managementapi.environment.exception.AndroidDevicePolicyInstallConsentDismissedException 如果使用者關閉安裝同意畫面。

com.google.android.managementapi.common.exceptions.InternalException

如果通話因內部錯誤而失敗。

prepareEnvironmentAsync

@RequiresApi(value = 28)
fun prepareEnvironmentAsync(
    request: PrepareEnvironmentRequest,
    notificationServiceComponentName: ComponentName?
): ListenableFuture<PrepareEnvironmentResponse>

準備裝置環境。

提示使用者安裝必要的 Android Device Policy 應用程式。如果使用者接受提示,系統就會繼續安裝。安裝成功後,系統會執行相關作業,確保 Android Device Policy 應用程式已就緒。

參數
notificationServiceComponentName: ComponentName?

擴充 NotificationReceiverService 的服務的 ComponentName。如果提供,則必須是屬於呼叫應用程式的有效元件,並在資訊清單中匯出。如要接收環境準備事件的通知,您必須:

  1. 在應用程式中實作 EnvironmentListener 介面。

  2. 提供如何處理收到的事件的實作方式。

  3. 擴充 NotificationReceiverService,並提供 EnvironmentListener 例項。

  4. 將擴充的 NotificationReceiverService 類別新增至 AndroidManifest.xml,並確認已匯出。

例如:

class MyEnvironmentListener : EnvironmentListener {
override fun onEnvironmentEvent(event: EnvironmentEvent) {
// Handle the environment event.
}
}

class MyNotificationReceiverService : NotificationReceiverService() {
override fun getPrepareEnvironmentListener(): EnvironmentListener? {
return MyEnvironmentListener()
}
}
傳回
ListenableFuture<PrepareEnvironmentResponse>

包裝結果的 ListenableFuture。這可能是