AMAPI prepareEnvironment() failing with ApiLevelException on Android 8 despite using DEVICE_POLICY_CONTROLLER role
Hi everyone,
I’m implementing a custom DPC (device owner) and integrating AMAPI locally on the device.
On Android 8 / 8.1, calling:
val request = PrepareEnvironmentRequest.builder()
.setRoles(
listOf(
Role.builder()
.setRoleType(Role.RoleType.DEVICE_POLICY_CONTROLLER)
.build()
)
)
.setAdmin(admin)
.build()
immediately fails with:
com.google.android.managementapi.common.exceptions.ApiLevelException
On Android 10 and above, I don't have this exception.
According to the AMAPI documentation:
If the device's SDK API level is insufficient for certain requested roles (this may be in addition to a general minimum API level requirement for the call itself).{@code Role.RoleType.DEVICE_POLICY_CONTROLLER} requires API level 23 or above. Any other roles require API level 28 or above.
I am using the latest AMAPI client library:
com.google.android.libraries.enterprise.amapi:amapi:1.7.0
Questions
Is AMAPI (EnvironmentClient + Device Policy Controller role) still officially supported on Android 8/8.1?
Any clarification on the real minimum supported API level for AMAPI prepareEnvironment() would be greatly appreciated, as the documentation suggests Android 8 should work, but the behavior indicates otherwise.
Thanks!