获取双卡手机的所有基站信息

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;
}
2个回答

1

我为其他遇到相同问题的人提供这个答案。 将CellInfo连接到SlotId的正确方法是通过收集活动订阅(SubscriptionInfo)的列表,该列表具有SlotIndex信息,并交叉引用其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;
        }
    }
}

-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;
}

请解释一下你的代码行,以便其他用户能够理解其功能。谢谢! - Ignacio Ara
这是TelephonyManager.getCellInfo()方法的实现,在这个方法中,所有手机将获取自己的AllCellInfo,因此TelephonyManager.getCellInfo()与SIM卡槽号码无关,它们获取所有手机的单元格信息。 - ppp wang
有没有办法将这些信息连接到slotId?谢谢。 - Zen

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接