有人知道从TelephonyManager.getAllCellInfo()返回的列表中的单元格索引是否与SIM插槽号有关吗?
我在使用Android 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;
}发布于 2019-03-27 19:08:23
只是为其他有同样问题的人添加这个答案。将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;
}
}
}发布于 2018-05-04 09:42:41
与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;
}https://stackoverflow.com/questions/49254591
复制相似问题