CellIdentityLte getCi() returning -1 in android

885 Views Asked by At

I have a method which returns cell id for LTE device, but on some devices it is returning -1. Here is the method:

    public int getCellId() {
    int cellId = Integer.MAX_VALUE;
    CellInfo cellInfo = null;
    List<CellInfo> allCellInfo = telephonyManager.getAllCellInfo();
    if(allCellInfo!= null && allCellInfo.size()>0)
        cellInfo = allCellInfo.get(0);
    if (cellInfo instanceof CellInfoLte) {
        CellInfoLte cellInfoLte = (CellInfoLte) cellInfo;
        if (cellInfoLte != null) {
            cellId = cellInfoLte.getCellIdentity().getCi();
        }
    }
    return cellId;
}
1

There are 1 best solutions below

2
On

You have it implemented correctly, unfortunately not all manufacturers implement all the Android APIs correctly, especially around the telephony area. Sometimes all the LTE values will be -1 also, sometimes just the CI.