问题
Does anyone know if the cell indexes on the list returned from TelephonyManager.getAllCellInfo()
are related to SIM slot numbers?
I'm using Android API 24...
After experimenting a bit, it seems that running the method updateCellInfo
- described below - always returns a list where it's first index corresponds to device's last SIM slot, and it's last index corresponds to device's first SIM slot.
Can anybody confirm this? Is this correlation plausible?
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;
}
回答1:
Just adding this answer for others having the same problem. The correct way of connecting CellInfo to SlotId is by gathering a List of active subscriptions (SubscriptionInfo), which have SlotIndex info, and cross referencing it's MNC code with CellInfo MNC code. It might be easier if you look at the code...
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;
}
}
}
回答2:
not related to SIM slot numbers, they get all phones cell info.
@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/getallcellinfo-in-dual-sim