Sunday, 4 October 2020

Device IMEI Number in Android 10 Q

 How to get Device IMEI Number ,below Android Version 10 it is easily get Device imei number nut After Android 10 version Android is not support to get device imei number , So using this below code we will get Device IMEI Number after Android 10

Give Permission in Menifest.xml file 


<uses-permission android:name="android.permission.READ_PHONE_STATE" />

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION">
</uses-permission>

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION">
</uses-permission>


TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
if (telephonyManager != null) {
try {
imei = telephonyManager.getImei();
txtimei.setText(imei);
} catch (Exception e) {
e.printStackTrace();
imei = Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID);
txtimei.setText("Device IMEI.... "+imei);
}
}
} else {
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.READ_PHONE_STATE}, 1010);
}
} else {
if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
if (telephonyManager != null) {
imei = telephonyManager.getDeviceId();
txtimei.setText("else and else....."+imei);
}
} else {
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.READ_PHONE_STATE}, 1010);
}
}
}catch(Exception e){
e.printStackTrace();
}



So , this is the code to get device imei number above android Q.

Here is the code  Get Device IMEI Number


No comments:

Post a Comment

Comments

Find Hours Diffrence in Kotlin

  In Kotlin, determining the difference in hours between two timestamps is a common task, especially in scenarios involving time-based calcu...