android获取基站信息(cid 和lac)

首先在AndroidManifest.xml文件里添加权限



TelephonyManager tel = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
@SuppressLint("MissingPermission")
CellLocation cel = tel.getCellLocation();
    if(tel.getPhoneType()==TelephonyManager.PHONE_TYPE_CDMA){//如果是电信卡的话
        CdmaCellLocation cdmaCellLocation = (CdmaCellLocation) cel;
        int cid = cdmaCellLocation.getBaseStationId();
        int lac = cdmaCellLocation.getNetworkId();
    }else {//如果是移动和联通的话  移动联通一致
        GsmCellLocation gsmCellLocation = (GsmCellLocation) cel;
        int cid = gsmCellLocation.getCid();
        int lac = gsmCellLocation.getLac();
    }

注意!!此程序没有插SIM卡的状态下会闪退,你们用的话自己加个抛异常的代码!

如果能帮你们解决问题就打个赏吧

android获取基站信息(cid 和lac)_第1张图片

 

你可能感兴趣的:(android获取基站信息(cid 和lac))