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。这有助于调用方了解环境是否已准备就绪。

getEnvironmentAsync

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

返回 Environment。这有助于调用方了解环境是否已准备就绪。

返回
ListenableFuture<Environment>

用于封装结果的 ListenableFuture。这个身份可以是以下任一项:

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。这可能是因为