Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I am getting IMEI null in Android Q?

Tags:

android

imei

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

is there any workaround for that?

like image 574
Aman Verma Avatar asked Mar 15 '19 00:03

Aman Verma


People also ask

How do I get my IMEI number Android?

Finding your IMEI number on your Android device Here's how to find your IMEI number in the settings on your Android device: Go to the Settings app. Scroll down and select About Phone. Scroll down to find your IMEI number.

How do I find my IMEI Android 10?

To view the IMEI number under Settings Find and tap Settings. Android 10 / 11 / 12: About phone → IMEI. Android 9: System → About phone → IMEI.

Is the IMEI the Android ID?

The android device ID is a unique alphanumeric code generated for your Android phone when you first set it up. This code basically identifies your device similar to how the IMEI number works. However, Android device ID is specifically used for identification purposes, instead of tracking your device.

Can we get IMEI number in Android programmatically?

To get IMEI (international mobile equipment identifier) and if It is above API level 26 then we get telephonyManager. getImei() as null so for that, we use ANDROID_ID as a Unique Identifier.


2 Answers

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

like image 130
takharsh Avatar answered Sep 21 '22 19:09

takharsh


I am late to post answer. I still believe my answer will help someone. Android 10 Restricted developer to Access IMEI number.

You can have a alternate solution by get Software ID. You can use software id as a unique id. Please find below code as i use in Application.

public static String getDeviceId(Context context) {   String deviceId;      if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {         deviceId = Settings.Secure.getString(                 context.getContentResolver(),                 Settings.Secure.ANDROID_ID);     } else {         final TelephonyManager mTelephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);         if (mTelephony.getDeviceId() != null) {             deviceId = mTelephony.getDeviceId();         } else {             deviceId = Settings.Secure.getString(                     context.getContentResolver(),                     Settings.Secure.ANDROID_ID);         }     }      return deviceId; } 
like image 35
Satish Avatar answered Sep 20 '22 19:09

Satish