To identify each devices uniquely I would like to use the IMEI (or ESN number for CDMA devices). How to access this programmatically?
For those looking for a Kotlin version, you can use something like this;
private fun telephonyService() {
val telephonyManager = getSystemService(TELEPHONY_SERVICE) as TelephonyManager
val imei = if (android.os.Build.VERSION.SDK_INT >= 26) {
Timber.i("Phone >= 26 IMEI")
telephonyManager.imei
} else {
Timber.i("Phone IMEI < 26")
telephonyManager.deviceId
}
Timber.i("Phone IMEI $imei")
}
NOTE: You must wrap telephonyService()
above with a permission check using checkSelfPermission or whatever method you use.
Also add this permission in the manifest file;