-1

Below are my code getting security exception from Android version 7 and onwards. I have added android.permission.READ_PHONE_STATE permission in manifest file and also added in runtime permissions also.

TelephonyManager tManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

String imeiNum= tManager.getDeviceId();
Natig Babayev
  • 3,128
  • 15
  • 23

2 Answers2

0

You're targeting api level 29. Since 29, it throws a SecurityException . getDeviceId() is deprecated since API 26, you should try getImei() ;

isaaaaame
  • 460
  • 4
  • 9
-1

If you want to get imei, you can try

TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    String imei = tm.getImei();
} else {
    String imei = tm.getDeviceId();
}
tadev
  • 204
  • 1
  • 5