Reputation: 23
TelephonyManager getSubscriberId()
and getSimSerialNumber()
return null in android Q!
I'm coding in java with android studio IDE!
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
telephonyManager.getSimSerialNumber(); //it is null
Upvotes: 0
Views: 3736
Reputation: 36
If your apk's targetsdk <30, you can get ICCID by the following method without any permission even in android 11.
Uri uri = Uri.parse("content://telephony/siminfo");
Cursor cursor = null;
ContentResolver contentResolver = getApplicationContext().getContentResolver();
cursor = contentResolver.query(uri,
new String[]{"_id", "sim_id", "imsi","icc_id","number","display_name"}, "0=0",
new String[]{}, null);
if (null != cursor) {
while (cursor.moveToNext()) {
String icc_id = cursor.getString(cursor.getColumnIndex("icc_id"));
String imsi_id = cursor.getString(cursor.getColumnIndex("imsi"));
String phone_num = cursor.getString(cursor.getColumnIndex("number"));
String display_name = cursor.getString(cursor.getColumnIndex("display_name"));
int sim_id = cursor.getInt(cursor.getColumnIndex("sim_id"));
int _id = cursor.getInt(cursor.getColumnIndex("_id"));
Log.d("Q_M", "icc_id-->" + icc_id);
Log.d("Q_M", "imsi_id-->" + imsi_id);
Log.d("Q_M", "phone_num-->" + phone_num);
Log.d("Q_M", "sim_id-->" + sim_id);
Log.d("Q_M", "display_name-->" + display_name);
}
}
Upvotes: 1
Reputation: 1
Also if are your app is can be selectable as default SMS app you can get this data without need any permissions. For set your app as the default SMS app please look that page
Upvotes: 0
Reputation: 3583
public String getSimSerialNumber () Returns the serial number of the SIM, if applicable. Return null if it is unavailable.
Requires Permission: READ_PRIVILEGED_PHONE_STATE, for the calling app to be the device or profile owner and have the READ_PHONE_STATE permission.
See the following link: getSerialNumber()
Upvotes: 0