android获取周围基站信息

来源:互联网 发布:nginx body filter 编辑:程序博客网 时间:2024/04/30 15:17
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;}
0 0
原创粉丝点击