我想要獲得具有多個SIM卡「雙卡」的Android設備上的網絡列表。當手機有雙卡雙待時獲得兩個網絡
我使用TelephonyManager類,但方法getNetworkType
僅返回第一個SIM卡「sim 1」的網絡。
我想要獲得具有多個SIM卡「雙卡」的Android設備上的網絡列表。當手機有雙卡雙待時獲得兩個網絡
我使用TelephonyManager類,但方法getNetworkType
僅返回第一個SIM卡「sim 1」的網絡。
我已經找到一個posible解決方案。我已經使用了Android的反射來調用例如TelephonyManager方法,如果我想要的數據網絡,我可以使用getDataNetworkType如下:
getNetworkTypeReflection(telephonyManager, "getDataNetworkType", slot, false);
private static String getNetworkTypeReflection(final TelephonyManager telephony, final String predictedMethodName, final int slotID, final boolean isPrivate) {
String result = null;
try {
final Class<?> telephonyClass = Class.forName(telephony.getClass().getName());
final Class<?>[] parameter = new Class[1];
parameter[0] = int.class;
final Method getSubtecnology;
if (slotID != -1) {
if (isPrivate) {
getSubtecnology = telephonyClass.getDeclaredMethod(predictedMethodName, parameter);
} else {
getSubtecnology = telephonyClass.getMethod(predictedMethodName, parameter);
}
} else {
if (isPrivate) {
getSubtecnology = telephonyClass.getDeclaredMethod(predictedMethodName);
} else {
getSubtecnology = telephonyClass.getMethod(predictedMethodName);
}
}
final Object obPhone;
final Object[] obParameter = new Object[1];
obParameter[0] = slotID;
if (getSubtecnology != null) {
if (slotID != -1) {
obPhone = getSubtecnology.invoke(telephony, obParameter);
} else {
obPhone = getSubtecnology.invoke(telephony);
}
if (obPhone != null) {
result = obPhone.toString();
}
}
} catch (Exception e) {
//e.printStackTrace();
return null;
}
return result;
}
的問題是,此選項僅適用於Android 5.1(API22 ),但只有在其他設備上需要使用Android 7.0(API24)。 如果有人有其他選擇,歡迎。
在Android Android 5.1(API22)之前沒有API。但那麼你有SubscriptionManager
和它的getActiveSubscriptionInfoList()
感謝您的回答,但與SubscriptionManager的問題是,不是每個SIM卡的返回網絡,或者如果它真的返回它,我不知道如何得到它 – efr