0

i am using GsmCellLocation to get LAC and cell id for 3G network with below code :
mCid = gmsCellLocation.getCid() & 0xffff;
mLac = gmsCellLocation.getLac();
and is there any library or formula how to get/calculate the correct LAC and cell id for LTE network (4G) ? Thanks.

Lim YC
  • 31
  • 2
  • 11

2 Answers2

1
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
List<CellInfo> cellInfoList = telephonyManager.getAllCellInfo();
for (int i = 0; i < cellInfoList.size(); i++) {
    if (cellInfoList.get(i) instanceof CellInfoLte) {
        CellInfoLte cellInfoLte = (CellInfoLte) cellInfoList.get(i);
        mCid = cellInfoLte.getCellIdentity().getCi();
        mLac = cellInfoLte.getCellIdentity().getTac();
    }
}

Note the method name, it is getCi for LTE. Also, getTac for LTE instead of getLac. See this answer for more.

Ananth
  • 2,597
  • 1
  • 29
  • 39
-1

I hope this might help you :

public class MobileInfoRecognizer {

    public String getCellInfo(CellInfo cellInfo) {
            String additional_info;
            if (cellInfo instanceof CellInfoGsm) {
                CellInfoGsm cellInfoGsm = (CellInfoGsm) cellInfo;
                CellIdentityGsm cellIdentityGsm = cellInfoGsm.getCellIdentity();
                additional_info = "cell identity " + cellIdentityGsm.getCid() + "\n"
                        + "Mobile country code " + cellIdentityGsm.getMcc() + "\n"
                        + "Mobile network code " + cellIdentityGsm.getMnc() + "\n"
                        + "local area " + cellIdentityGsm.getLac() + "\n";
            } else if (cellInfo instanceof CellInfoLte) {
                CellInfoLte cellInfoLte = (CellInfoLte) cellInfo;
                CellIdentityLte cellIdentityLte = cellInfoLte.getCellIdentity();
                additional_info = "cell identity " + cellIdentityLte.getCid() + "\n"
                        + "Mobile country code " + cellIdentityLte.getMcc() + "\n"
                        + "Mobile network code " + cellIdentityLte.getMnc() + "\n"
                        + "physical cell " + cellIdentityLte.getPci() + "\n"
                        + "Tracking area code " + cellIdentityLte.getTac() + "\n";
            } else if (cellInfo instanceof CellInfoWcdma){
                CellInfoWcdma cellInfoWcdma = (CellInfoWcdma) cellInfo;
                CellIdentityWcdma cellIdentityWcdma = cellInfoWcdma.getCellIdentity();
                additional_info = "cell identity " + cellIdentityWcdma.getCid() + "\n"
                        + "Mobile country code " + cellIdentityWcdma.getMcc() + "\n"
                        + "Mobile network code " + cellIdentityWcdma.getMnc() + "\n"
                        + "local area " + cellIdentityWcdma.getLac() + "\n";
            }
            return additional_info;
    }
}
Optional
  • 4,387
  • 4
  • 27
  • 45
  • There is no method as getCid() in CellIdentityLte class, which you have called on cellIdentityLte. – Ananth Aug 02 '19 at 07:29