我想在双SIM卡手机中获取SIM卡的SIM卡序列号/双卡号码。是否有办法得到它们?提前致谢。Android:如何获取双SIM卡手机中的SIM卡的SIM卡号码
4
A
回答
3
import java.lang.reflect.Method;
import android.content.Context;
import android.telephony.TelephonyManager;
public final class TelephonyInfo {
private static TelephonyInfo telephonyInfo;
private String imeiSIM1;
private String imeiSIM2;
private boolean isSIM1Ready;
private boolean isSIM2Ready;
public String getImeiSIM1() {
return imeiSIM1;
}
/*public static void setImeiSIM1(String imeiSIM1) {
TelephonyInfo.imeiSIM1 = imeiSIM1;
}*/
public String getImeiSIM2() {
return imeiSIM2;
}
/*public static void setImeiSIM2(String imeiSIM2) {
TelephonyInfo.imeiSIM2 = imeiSIM2;
}*/
public boolean isSIM1Ready() {
return isSIM1Ready;
}
/*public static void setSIM1Ready(boolean isSIM1Ready) {
TelephonyInfo.isSIM1Ready = isSIM1Ready;
}*/
public boolean isSIM2Ready() {
return isSIM2Ready;
}
/*public static void setSIM2Ready(boolean isSIM2Ready) {
TelephonyInfo.isSIM2Ready = isSIM2Ready;
}*/
public boolean isDualSIM() {
return imeiSIM2 != null;
}
private TelephonyInfo() {
}
public static TelephonyInfo getInstance(Context context){
if(telephonyInfo == null) {
telephonyInfo = new TelephonyInfo();
TelephonyManager telephonyManager = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE));
telephonyInfo.imeiSIM1 = telephonyManager.getDeviceId();;
telephonyInfo.imeiSIM2 = null;
try {
telephonyInfo.imeiSIM1 = getDeviceIdBySlot(context, "getDeviceIdGemini", 0);
telephonyInfo.imeiSIM2 = getDeviceIdBySlot(context, "getDeviceIdGemini", 1);
} catch (GeminiMethodNotFoundException e) {
e.printStackTrace();
try {
telephonyInfo.imeiSIM1 = getDeviceIdBySlot(context, "getDeviceId", 0);
telephonyInfo.imeiSIM2 = getDeviceIdBySlot(context, "getDeviceId", 1);
} catch (GeminiMethodNotFoundException e1) {
//Call here for next manufacturer's predicted method name if you wish
e1.printStackTrace();
}
}
telephonyInfo.isSIM1Ready = telephonyManager.getSimState() == TelephonyManager.SIM_STATE_READY;
telephonyInfo.isSIM2Ready = false;
try {
telephonyInfo.isSIM1Ready = getSIMStateBySlot(context, "getSimStateGemini", 0);
telephonyInfo.isSIM2Ready = getSIMStateBySlot(context, "getSimStateGemini", 1);
} catch (GeminiMethodNotFoundException e) {
e.printStackTrace();
try {
telephonyInfo.isSIM1Ready = getSIMStateBySlot(context, "getSimState", 0);
telephonyInfo.isSIM2Ready = getSIMStateBySlot(context, "getSimState", 1);
} catch (GeminiMethodNotFoundException e1) {
//Call here for next manufacturer's predicted method name if you wish
e1.printStackTrace();
}
}
}
return telephonyInfo;
}
private static String getDeviceIdBySlot(Context context, String predictedMethodName, int slotID) throws GeminiMethodNotFoundException {
String imei = 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){
imei = ob_phone.toString();
}
} catch (Exception e) {
e.printStackTrace();
throw new GeminiMethodNotFoundException(predictedMethodName);
}
return imei;
}
private static boolean getSIMStateBySlot(Context context, String predictedMethodName, int slotID) throws GeminiMethodNotFoundException {
boolean isReady = false;
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 getSimStateGemini = telephonyClass.getMethod(predictedMethodName, parameter);
Object[] obParameter = new Object[1];
obParameter[0] = slotID;
Object ob_phone = getSimStateGemini.invoke(telephony, obParameter);
if(ob_phone != null){
int simState = Integer.parseInt(ob_phone.toString());
if(simState == TelephonyManager.SIM_STATE_READY){
isReady = true;
}
}
} catch (Exception e) {
e.printStackTrace();
throw new GeminiMethodNotFoundException(predictedMethodName);
}
return isReady;
}
private static class GeminiMethodNotFoundException extends Exception {
private static final long serialVersionUID = -996812356902545308L;
public GeminiMethodNotFoundException(String info) {
super(info);
}
}
}
private void isDualSimOrNot(){
TelephonyInfo telephonyInfo = TelephonyInfo.getInstance(this);
String imeiSIM1 = telephonyInfo.getImeiSIM1();
String imeiSIM2 = telephonyInfo.getImeiSIM2();
boolean isSIM1Ready = telephonyInfo.isSIM1Ready();
boolean isSIM2Ready = telephonyInfo.isSIM2Ready();
boolean isDualSIM = telephonyInfo.isDualSIM();
Log.i("Dual = "," IME1 : " + imeiSIM1 + "\n" +
" IME2 : " + imeiSIM2 + "\n" +
" IS DUAL SIM : " + isDualSIM + "\n" +
" IS SIM1 READY : " + isSIM1Ready + "\n" +
" IS SIM2 READY : " + isSIM2Ready + "\n");
}
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
+0
它返回两个SIM卡的IMEI,但我需要SIM卡ID。 – Salman
+0
是否适用于SIM卡 –
+1
这对双卡手机无效,还有一个来源是http://stackoverflow.com/questions/14517338/android-check-whether-the-phone-is-dual- SIM卡 –
相关问题
- 1. Android获取手机SIM卡号码
- 2. 获取SimOperatorName的双SIM卡android手机
- 3. 检测双SIM卡Android手机中两张SIM卡的状态
- 4. 双SIM卡Android
- 5. Android:如何在Android中获取两张SIM卡的SIM卡ID?
- 6. 双SIM卡更改默认SIM卡
- 7. 从双SIM卡手机发送短信到另一张SIM卡
- 8. 从双SIM卡手机中的每张SIM卡分别读取联系人
- 9. iPhone SIM卡号码
- 10. 在SIM卡中比较旧SIM卡号码和新SIM卡交换需求
- 11. 如何从双SIM卡手机中获得两个IMEI号码?
- 12. 如何在双SIM卡插槽中更改SIM卡的信息?
- 13. Android:在双SIM手机getSimCountryIso()返回哪个SIM卡?
- 14. 如何在双SIM卡手机android中获取SIMOperator?
- 15. 如何获得双SIM卡手机号码?
- 16. 获取双SIM卡android移动设备上的两个SIM卡插槽的IMEI
- 17. 如何从双SIM卡手机Android获取运营商名称?
- 18. Android:如何获得SIM卡手机号码
- 19. 短信管理双SIM卡手机?
- 20. 如果我的android手机有两张SIM卡,如何获取手机号码?
- 21. 在Android中使用Airtel提供商SIM卡时无法获得SIM卡号码?
- 22. 三星android 6.0如何获得双SIM卡通话记录与SIM卡槽ID?
- 23. 获取所有SIM卡电话号码
- 24. 选择SIM卡发送双SIM卡上的短信索尼xperia
- 25. 的SIM卡
- 26. 如何在Android中获得双SIM卡IMEI号码
- 27. android sim卡听众
- 28. 检测双卡手机中的当前/主SIM卡
- 29. 如何在Android中获取双SIM卡序列号
- 30. 虚拟实体SIM卡到Android手机
可能吗? – Harshid