Kotlin Accssing Android Device ID (KAADI)

Hi guys, this time I want to share about the problem I am currently facing, namely how to get a unique ID from an Android device.

At first, I was given a case study by my boss to limit only certain devices that can install the applications that we develop and distribute, so the backend team needs to collect the unique identity of each device that is allowed (whitelist).

There are several options we are researching, including:

  1. IMEI (impossible)
  2. Device ID
  3. Mac Address

For IMEI, it is not possible because it requires special permission from the platform owner, in this case, usually only the cellphone's default application (app platform) has the right.

Solution

Long story short, we used another alternative, one of which was Device ID, and the way we did it was by creating an extension function as follows.

@SuppressLint( "HardwareIds" )
 fun Context.deviceId(): String = Settings.Secure.getString( this .contentResolver, Settings.Secure.ANDROID_ID)

Post a Comment

Previous Next

نموذج الاتصال