Getallcellinfo In Dual Sim
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
Solution 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 = newArrayList<>(telephonyManager.getAllCellInfo());
SubscriptionManagersubscriptionManager= SubscriptionManager.from(getActivity());
List<SubscriptionInfo> activeSubscriptionInfoList = subscriptionManager.getActiveSubscriptionInfoList();
SubscriptionInfo subscriptionInfo;
for (inti=0; i < activeSubscriptionInfoList.size(); i++) {
SubscriptionInfotemp= activeSubscriptionInfoList.get(i);
if (temp.getSimSlotIndex() == slotIndex) {
subscriptionInfo=temp;
break;
}
}
for (intindex=0; index < allCellInfo.size(); index++) {
intmnc=0;
CellInfotemp= allCellInfo.get(index);
StringcellType= checkCellType(temp);
if (cellType == "GSM") {
CellIdentityGsmidentity= (((CellInfoGsm) temp).getCellIdentity());
mnc = identity.getMnc();
} elseif (cellType == "WCDMA") {
CellIdentityWcdmaidentity= (((CellInfoWcdma) temp).getCellIdentity());
mnc = identity.getMnc();
} elseif (cellType == "LTE") {
CellIdentityLteidentity= (((CellInfoLte) temp).getCellIdentity());
mnc = identity.getMnc();
}
if (mnc == subscriptionInfo.getMnc()) {
return temp;
}
}
}
Solution 2:
not related to SIM slot numbers, they get all phones cell info.
@Overridepublic List<CellInfo> getAllCellInfo(String callingPackage) {
if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
callingPackage, Binder.getCallingUid(), "getAllCellInfo")) {
returnnull;
}
if (DBG_LOC) log("getAllCellInfo: is active user");
WorkSourceworkSource= getWorkSource(null, Binder.getCallingUid());
List<CellInfo> cellInfos = newArrayList<CellInfo>();
for (Phone phone : PhoneFactory.getPhones()) {
final List<CellInfo> info = phone.getAllCellInfo(workSource);
if (info != null) cellInfos.addAll(info);
}
return cellInfos;
}
Post a Comment for "Getallcellinfo In Dual Sim"