双SIM卡中的getAllCellInfo

问题描述 投票:2回答:2

有谁知道从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;
}
android telephony telephonymanager cellinfo
2个回答
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;
}

0
投票

只是为有相同问题的其他人添加此答案。将CellInfo连接到SlotId的正确方法是收集具有SlotIndex信息的活动订阅列表(SubscriptionInfo),并使用CellInfo MNC代码交叉引用它的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;
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.