I\'m getting the IMEI and device Id\'s, so here I am getting a problem getDeviceId() is deprecated.
TelephonyManager tm = (Telephon
Kotlin Code for getting DeviceId ( IMEI ) with handling with permission & compatibility check for all android versions :
val telephonyManager = getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE)
== PackageManager.PERMISSION_GRANTED) {
// Permission is granted
val imei : String? = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
telephonyManager.imei
} else { // older OS versions
telephonyManager.getDeviceId()
}
imei?.let {
Log.i("Log", "DeviceId=$imei" )
}
} else { // Permission is not granted
}
Also add this permission to AndroidManifest.xml :