0

我正在使用 GsmCellLocation 使用以下代码获取 3G 网络的 LAC 和小区 ID:
mCid = gmsCellLocation.getCid() & 0xffff;
mLac = gmsCellLocation.getLac();
是否有任何库或公式如何获取/计算 LTE 网络 (4G) 的正确 LAC 和小区 ID?谢谢。

4

2 回答 2

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();
    }
}

请注意方法名称,它getCi适用于 LTE。此外,getTac对于 LTE 而不是getLac. 有关更多信息,请参阅答案。

于 2019-08-02T09:53:37.370 回答
-1

我希望这可以帮助你:

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;
    }
}
于 2017-11-08T10:57:38.423 回答