简体   繁体   中英

How to get enrollment-specific identifier of an android device?

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 ()
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 {
            ""
        }
    }

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM