我想检查用户设备是否为双卡。我有一个 TelephonyInfo 类。它的这个类的getInstance方法:
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();
try {
telephonyInfo.imeiSIM1 = getDeviceIdBySlot(context, "getDeviceIdDs", 0);
telephonyInfo.imeiSIM2 = getDeviceIdBySlot(context, "getDeviceIdDs", 1);
} catch (GeminiMethodNotFoundException e2) {
//Call here for next manufacturer's predicted method name if you wish
e2.printStackTrace();
}
}
}
try {
telephonyInfo.networkOperatorName1 = getDeviceIdBySlot(context, "getNetworkOperatorNameGemini", 0);
telephonyInfo.networkOperatorName2 = getDeviceIdBySlot(context, "getNetworkOperatorNameGemini", 1);
} catch (GeminiMethodNotFoundException e) {
e.printStackTrace();
try {
telephonyInfo.networkOperatorName1 = getDeviceIdBySlot(context, "getNetworkOperatorName", 0);
telephonyInfo.networkOperatorName2 = getDeviceIdBySlot(context, "getNetworkOperatorName", 1);
} catch (GeminiMethodNotFoundException e1) {
//Call here for next manufacturer's predicted method name if you wish
e1.printStackTrace();
try {
telephonyInfo.networkOperatorName1 = getDeviceIdBySlot(context, "getNetworkOperatorNameDs", 0);
telephonyInfo.networkOperatorName2 = getDeviceIdBySlot(context, "getNetworkOperatorNameDs", 1);
} catch (GeminiMethodNotFoundException e2) {
//Call here for next manufacturer's predicted method name if you wish
e2.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;
}
我用这种方法检查设备状态:
public boolean isDualSIM() {
return imeiSIM2 != null;
}
最后我以这种方式使用这个类:
TelephonyInfo telephonyInfo = TelephonyInfo.getInstance(mActivity);
isDualSimCard = telephonyInfo.isDualSIM();
我将 Sony experia z2 与 android 5.1.1 一起使用,此设备不是双卡,但 isDualSim() 方法返回 true。
我的代码有什么问题?