Я получил cra sh на Android 10 устройствах при получении IMEI от Real Devices. Для справки я добавил фрагмент кода ниже. Он спрашивал разрешение READ_PHONE_STATE при запуске приложения, и я включил разрешение. На нем все отлично работает.
if (ContextCompat.checkSelfPermission(SplashScreen.this,
Manifest.permission.READ_PHONE_STATE)
!= PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(SplashScreen.this,
Manifest.permission.READ_PHONE_STATE)) {
showPermissionMessage();
} else {
ActivityCompat.requestPermissions(SplashScreen.this,
new String[]{Manifest.permission.READ_PHONE_STATE},
REQUEST_PHONE_STATE);
}
} else {
getDeviceId();
}
} else {
getDeviceId();
}```
I have checked with the permission was enabled or not. In this case it shows Permission enabled.But i got security exception only. Getting device id was receiving the IMEI value from Telephony manager.
```TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
if (checkSelfPermission(Manifest.permission.READ_PHONE_STATE) !=
PackageManager.PERMISSION_GRANTED) {
return;
}
}
try {
StoredDatas.getInstance().setStrIMEINumber(tm.getDeviceId());
} catch (Exception e) {
StoredDatas.getInstance().setStrIMEINumber("123456");
} finally {
Log.e("appSample", "IMEI: " + StoredDatas.getInstance().getStrIMEINumber());
}```
In this I got the crash on getting Device id, so i have done with static value as of now. I have tested my code with Samsung Tab 10 version. I have checked with the settings on mobile, it shows the permissions are enabled only.