0

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;
}
Rajat Mehra
  • 1,462
  • 14
  • 19

1 Answers1

0

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.

Anonsage
  • 8,030
  • 5
  • 48
  • 51
  • Thanks for the answer. I am using Samsung Core Prime and LG Spirit, most of the time it is returning valid Cell Id but on some cases it is returning -1. What could be the reason for this? Can you give some reference for this? – Rajat Mehra Aug 27 '15 at 08:08
  • My main reference is from personal experience with a published signal app of over 300k downloads. Basically, I don't trust most of the telephony documentation for returned values. Also, even when the public APIs sometimes return -1, the system engineering screen can show the correct values. In one case, as user was able to get the LTE values back after forcing non-LTE mode, then going back to LTE mode. I'm also still researching other workarounds. – Anonsage Aug 27 '15 at 15:30