I try below code but it return null for both.
TelephonyManager telephonyInfo = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE));
telephonyInfo.serialSIM1 = telephonyManager.getSimSerialNumber();
telephonyInfo.serialSIM2 = null;
try {
telephonyInfo.serialSIM1 = getSerialBySlot(context, "getSimSerialNumberGemini", 0);
telephonyInfo.serialSIM2 = getSerialBySlot(context, "getSimSerialNumberGemini", 1);
} catch (GeminiMethodNotFoundException e) {
e.printStackTrace();
try {
telephonyInfo.serialSIM1 = getSerialBySlot(context, "getSimSerialNumber", 0);
telephonyInfo.serialSIM2 = getSerialBySlot(context, "getSimSerialNumber", 1);
} catch (GeminiMethodNotFoundException e1) {
//Call here for next manufacturer's predicted method name if you wish
e1.printStackTrace();
}
}
private static String getSerialBySlot(Context context, String predictedMethodName, int slotID) throws GeminiMethodNotFoundException {
String lsSerialNumber = null;
TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
try{
Class<?> telephonyClass = Class.forName(telephony.getClass().getName());
Class<?>[] parameter = new Class[1];
parameter[0] = int.class;
Method getSimID = telephonyClass.getMethod(predictedMethodName, parameter);
Object[] obParameter = new Object[1];
obParameter[0] = slotID;
Object ob_phone = getSimID.invoke(telephony, obParameter);
if(ob_phone != null){
lsSerialNumber = ob_phone.toString();
}
} catch (Exception e) {
e.printStackTrace();
throw new GeminiMethodNotFoundException(predictedMethodName);
}
return lsSerialNumber;
}
private static class GeminiMethodNotFoundException extends Exception {
private static final long serialVersionUID = -996812356902545308L;
public GeminiMethodNotFoundException(String info) {
super(info);
}
}
Then use it.
String getSerialNumber1 = telephonyInfo.getSerialSIM1();
String getSerialNumber2 = telephonyInfo.getSerialSIM2();
Log.i(TAG, "state getSerialNumber1 : " + getSerialNumber1);
Log.i(TAG, "state getSerialNumber2 : " + getSerialNumber2);
Below is the log which is got in logcat
09-16 07:20:07.042 6973-6973/app.myApp I/SimChangeReceiver: state getSerialNumber1 : null
09-16 07:20:07.042 6973-6973/app.myApp I/SimChangeReceiver: state getSerialNumber2 : null
I can get IMEI and the dual sim or not. I search around for the related question,But I did not found any other method.
Instead of using getSimSerialNumber, you can use SubscriptionManager.