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; }
android获取周围基站信息
最新推荐文章于 2024-12-08 10:56:23 发布