I am getting IMEI null in Android Q?

2019-06-23 23:14发布

I am getting the IMEI ID null from the telephonymanager. What to do?

is there any workaround for that?

标签: android imei
2条回答
【Aperson】
2楼-- · 2019-06-23 23:47

For getting the IMEI these are also the steps:

1) Define permission in manifest:

<uses-permission android:name="android.permission.READ_PHONE_STATE" />

or if API level is > 22

ContextCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE)

2) Get the IMEI in java using TelephonyManager

((TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId()

Compile both (1) & (2) points:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
            imei = ((TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();
        }
    } else {
        imei = ((TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();
    }
查看更多
smile是对你的礼貌
3楼-- · 2019-06-24 00:00

Android Q has restricted to access for both IMEI and serial no. It is available only for platform and apps with special carrier permission. Also the permission READ_PRIVILEGED_PHONE_STATE is not available for non platform apps.

If you try to access it throws below exception

java.lang.SecurityException: getImeiForSlot: The user 10180 does not meet the requirements to access device identifiers.

Please refer documentation: https://developer.android.com/preview/privacy/data-identifiers#device-ids

Also refer Issue

查看更多
登录 后发表回答