skip to Main Content

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.

2

Answers


  1. Chosen as BEST ANSWER

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


  2. 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?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search