ユーザー端末がデュアルSIMかどうかを確認したい。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();
Android 5.1.1 で Sony experia z2 を使用しています。このデバイスはデュアル SIM ではありませんが、isDualSim() メソッドは true を返します。
私のコードで何が間違っていますか?