Home > Software engineering >  How get IMEI of device?
How get IMEI of device?

Time:07-12

I a beginner in android development and I try to get device IMEI but I have a problem of permission.

I don't have android.permission.READ_PRIVILEGED_PHONE_STATE property in my project but the function getImei() of TelephonyManger.java require this permission.

How can I resolve this? I am a little lost.

CodePudding user response:

try use below code in kotlin.

val telephonyManager = getSystemService(Context.TELEPHONY_SERVICE) as
     TelephonyManager
     if (ActivityCompat.checkSelfPermission(this@MainActivity,
     Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this@MainActivity,
        arrayOf(Manifest.permission.READ_PHONE_STATE), REQUEST_CODE)
        return@setOnClickListener
     }  
     IMEINumber = telephonyManager.deviceId
     

this link would be helpful. How to get the device's IMEI/ESN programmatically in android?

CodePudding user response:

The answer is sad. We can't !

Like @Nitsh said, "The READ_PRIVILEGED_PHONE_STATE permission is only granted to apps signed with the platform key and privileged system apps".

  • Related