I want to get unique identifiers like Android Device ID, IMEI, or MAC address from an Android phone with Android version 11 using Java.
Can someone help? I need just either one unique identifier.
This is the code that I use to get IMEI:
public String getIMEI() {
Context context = null;
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
Log.i("Testing: ", telephonyManager.getImei());
return telephonyManager.getImei();
}
And this is the error message that I got:
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.content.Context.getSystemService(java.lang.String)' on a null object reference
As of the API 29, Google introduced new security policies to the
TelephonyManager.getImeiAPI. So it won't be available for 3rd party apps for security reasons.Look at what is mentioned in the API's description: