android获取周围基站信息

该博客介绍了一段Java代码,用于在Android设备上获取周围基站(GSM、LTE、CDMA)的详细信息,包括MCC(移动国家代码)、MNC(移动网络代码)、LAC(位置区代码)、CID(小区标识)以及RSSI(信号强度)。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

public static List<GsmInfo> getGsmInfoList(Context context) {
    TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    List<CellInfo> cellInfoList = manager.getAllCellInfo();
    List<GsmInfo> gsmInfoList = new ArrayList<>();
    if (cellInfoList != null) {
        L.e("cellInfoList.size="+cellInfoList.size());
        GsmInfo gsmInfo;
        for (CellInfo info : cellInfoList) {
            L.e("info.toString():" + info.toString());
           if (info.toString().contains("CellInfoLte")) {
               CellInfoLte cellInfoLte = (CellInfoLte) info;
               CellIdentityLte cellIdentityLte = cellInfoLte.getCellIdentity();

               gsmInfo = new GsmInfo();
               gsmInfo.setMcc(cellIdentityLte.getMcc());
               gsmInfo.setMnc(cellIdentityLte.getMnc());
               gsmInfo.setLac(cellIdentityLte.getTac());
               gsmInfo.setCid(cellIdentityLte.getCi());
               gsmInfo.setRssi(cellInfoLte.getCellSignalStrength().getDbm());

               gsmInfoList.add(gsmInfo);
           } else if (info.toString().contains("CellInfoGsm")) {
               CellInfoGsm cellInfoGsm = (CellInfoGsm) info;
               CellIdentityGsm cellIdentityGsm = cellInfoGsm.getCellIdentity();

               gsmInfo = new GsmInfo();
               gsmInfo.setMcc(cellIdentityGsm.getMcc());
               gsmInfo.setMnc(cellIdentityGsm.getMnc());
               gsmInfo.setLac(cellIdentityGsm.getLac());
               gsmInfo.setCid(cellIdentityGsm.getCid());
               gsmInfo.setRssi(cellInfoGsm.getCellSignalStrength().getDbm());
               gsmInfoList.add(gsmInfo);
           } else if (info.toString().contains("CellInfoCdma")) {
               CellInfoCdma cellInfoCdma = (CellInfoCdma) info;
               CellIdentityCdma cellIdentityCdma = cellInfoCdma.getCellIdentity();

               gsmInfo = new GsmInfo();
               gsmInfo.setMcc(460);
               gsmInfo.setMnc(0);
               gsmInfo.setLac(0);
               gsmInfo.setCid(cellIdentityCdma.getBasestationId());
               gsmInfo.setRssi(cellInfoCdma.getCellSignalStrength().getDbm());
               gsmInfoList.add(gsmInfo);
           }
        }
    } else {
        L.e("cellInfoList == null");
    }

    return gsmInfoList;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值