首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >双SIM中的getAllCellInfo

双SIM中的getAllCellInfo
EN

Stack Overflow用户
提问于 2018-03-13 11:06:37
回答 2查看 1.4K关注 0票数 3

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

我在使用Android 24.

在进行了一些实验之后,运行下面描述的方法updateCellInfo似乎总是返回一个列表,其中第一个索引对应于设备的最后一个SIM槽,而它的最后一个索引对应于设备的第一个SIM插槽。

有人能证实这一点吗?这种关联可信吗?

代码语言:javascript
复制
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;
}
EN

回答 2

Stack Overflow用户

发布于 2019-03-27 19:08:23

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

代码语言:javascript
复制
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
EN

Stack Overflow用户

发布于 2018-05-04 09:42:41

与SIM插槽号码无关,他们会得到所有的手机信息。

代码语言:javascript
复制
@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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49254591

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档