双SIM卡中的getAllCellInfo

时间:2018-03-13 11:06:38

标签: android telephony telephonymanager cellinfo

有人知道从TelephonyManager.getAllCellInfo()返回的列表中的单元格索引是否与SIM插槽号相关?

我正在使用Android API 24 ...

经过实验后,似乎运行方法updateCellInfo - 如下所述 - 总是返回一个列表,其中第一个索引对应于设备的最后一个SIM卡插槽,它的最后一个索引对应于设备的第一个SIM卡插槽。

任何人都可以证实吗?这种相关性是否合理?

private ArrayList<CellInfo> updateCellInfo(ArrayList<CellInfo> cellInfo)
{
    //Create new ArrayList
    ArrayList<CellInfo> cellInfos= new ArrayList<>();

    //cellInfo is obtained from telephonyManager.getAllCellInfo()
    if(cellInfo.size()!=0)
    {
        for (int i = 0; i < cellInfo.size(); i++)
        {
            //Return registered cells only
            int index=0;
            CellInfo temp=cellInfo.get(i);
            if (temp.isRegistered())
            {
                cellInfos.add(index, temp);
                index++;
            }
        }
    }

    return cellInfos;
}

2 个答案:

答案 0 :(得分:0)

与SIM卡插槽号无关,它们可以获取所有手机的小区信息。

@Override
public List<CellInfo> getAllCellInfo(String callingPackage) {
    if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
            callingPackage, Binder.getCallingUid(), "getAllCellInfo")) {
        return null;
    }

    if (DBG_LOC) log("getAllCellInfo: is active user");
    WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
    List<CellInfo> cellInfos = new ArrayList<CellInfo>();
    for (Phone phone : PhoneFactory.getPhones()) {
        final List<CellInfo> info = phone.getAllCellInfo(workSource);
        if (info != null) cellInfos.addAll(info);
    }
    return cellInfos;
}

答案 1 :(得分:0)

只需为具有相同问题的其他人添加此答案即可。 将CellInfo连接到SlotId的正确方法是收集具有SlotIndex信息的活动订阅列表(SubscriptionInfo),并将其MNC代码与CellInfo MNC代码交叉引用。 如果您看一下代码,可能会更容易...

private CellInfo getSlotCellInfo(int slotIndex){
    ArrayList<CellInfo> allCellInfo = new ArrayList<>(telephonyManager.getAllCellInfo());
    SubscriptionManager subscriptionManager = SubscriptionManager.from(getActivity());
    List<SubscriptionInfo> activeSubscriptionInfoList = subscriptionManager.getActiveSubscriptionInfoList();
    SubscriptionInfo subscriptionInfo;

    for (int i = 0; i < activeSubscriptionInfoList.size(); i++) {
        SubscriptionInfo temp = activeSubscriptionInfoList.get(i);
        if (temp.getSimSlotIndex() == slotIndex) {
            subscriptionInfo=temp;
            break;
        }
    }

    for (int index = 0; index < allCellInfo.size(); index++) {
        int mnc = 0;
        CellInfo temp = allCellInfo.get(index);
        String cellType = checkCellType(temp);
        if (cellType == "GSM") {
            CellIdentityGsm identity = (((CellInfoGsm) temp).getCellIdentity());
            mnc = identity.getMnc();
        } else if (cellType == "WCDMA") {
            CellIdentityWcdma identity = (((CellInfoWcdma) temp).getCellIdentity());
            mnc = identity.getMnc();
        } else if (cellType == "LTE") {
            CellIdentityLte identity = (((CellInfoLte) temp).getCellIdentity());
            mnc = identity.getMnc();
        }
        if (mnc == subscriptionInfo.getMnc()) {
            return temp;
        }
    }
}