3

有谁知道返回的列表中的单元格索引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;
}
4

2 回答 2

1

只需为遇到相同问题的其他人添加此答案。将 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;
        }
    }
}
于 2019-03-27T19:08:23.193 回答
-1

与 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;
}
于 2018-05-04T09:42:41.573 回答