我想检查用户设备是否为双卡。 我有一个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。
我的代码出了什么问题?