I have an app where I identify each device with the number IMEI
,
The problem is that to request this number, androiod shows a window to the user indicating that if I grant permission to access the calls and the state of the phone. So many users say no
This is a problem because without this code I can not identify devices or associate a device with a user.
Is there any way to request the imei without permissions? or to request another unique device code?
The code I use is the following:
public void getImeiFunc() {
int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE);
if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_PHONE_STATE}, REQUEST_READ_PHONE_STATE);
}
else {
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String imei;
if (Build.VERSION.SDK_INT >= 26) {
imei = telephonyManager.getImei(0);
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
imei = telephonyManager.getDeviceId(0);
} else {
imei = telephonyManager.getDeviceId();
}
}
}
}