0
The methods below are not effective to capture the IMEI of all Android versions.
private String getIMEINumber() {
String IMEINumber = "";
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
TelephonyManager telephonyMgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
IMEINumber = telephonyMgr.getImei(0);
} else {
IMEINumber = telephonyMgr.getDeviceId();
}
}
return IMEINumber;
}
public static String getUniqueIMEIId(Context context) {
try {
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return "";
}
String imei = telephonyManager.getImei();
Log.e("imei", "=" + imei);
if (imei != null && !imei.isEmpty()) {
return imei;
} else {
return android.os.Build.SERIAL;
}
} catch (Exception e) {
e.printStackTrace();
}
return "not_found";
}
Good morning, man, I think you better stop using the IMEI. Google has been saying that from a certain time they will take away the applications that still use the IMEI. I advise you to use Advertisingid(http://www.androiddocs.com/google/play-services/id.html).
– João Victor Santana
Thank you João Vitor.
– Silvio