0

How to get the enrollment-specific identifier of a device, which is guaranteed to be the same value for the same device, enrolled into the same organization by the same managing app.

How to use the getEnrollmentSpecificId () method (added in API level 31) in Kotlin?

public String getEnrollmentSpecificId ()
Sweta Jain
  • 3,248
  • 6
  • 30
  • 50

2 Answers2

0
public String getEnrollmentSpecificId ()

It returns an enrollment-specific identifier of this device, which is guaranteed to be the same value for the same device, enrolled into the same organization by the same managing app. This identifier uniquely identifies individual devices within the same organization. The identifier would be consistent even if the work profile is removed and enrolled again (to the same organization), or the device is factory reset and re-enrolled.

Usage:

    fun getEnrollmentSpecificId(): String {
        val policy = getSystemService(Context.DEVICE_POLICY_SERVICE) as DevicePolicyManager
        return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
            try {
                policy.enrollmentSpecificId
            } catch (securityException: SecurityException) {
                print(securityException.message)
                ""
            }
        } else {
            ""
        }
    }
Sweta Jain
  • 3,248
  • 6
  • 30
  • 50
0

Here is the documentation about it

Only availabla form Android 12. And this can only be called by the Profile Owner or Device Owner, if the setOrganizationId(java.lang.String) was previously called

fun getEnrollmentSpecificId(): String {
    val policy = getSystemService(Context.DEVICE_POLICY_SERVICE) as DevicePolicyManager
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
        try {
            policy.setOrganizationId(ORGANIZATION_ID)
            return policy.enrollmentSpecificId
        } catch (securityException: SecurityException) {
        }
    }
    return ""
}