我为3G网络获得了错误的小区ID,为2G获得了正确的小区ID值,
我不明白我要去哪里错了。请帮忙

TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        GsmCellLocation cellLocation = (GsmCellLocation) telephonyManager
                .getCellLocation();

        //Cell Id, LAC
        int cid = cellLocation.getCid();
        int lac = cellLocation.getLac();

        //MCC
        String MCC =telephonyManager.getNetworkOperator();
        int mcc = Integer.parseInt(MCC.substring(0, 3));
        String mcc1 = String.valueOf(mcc);

        //Operator name
        String operatoprName = telephonyManager.getNetworkOperatorName();


我还对AndroiManifest.xml文件ACCESS_COARSE_LOCATION,ACCESS_NETWORK_STATE授予了权限

最佳答案

解决方案在以下线程中突出显示:Android: CellID not available on all carriers?

简而言之,在3G网络中,您需要使用0xffff屏蔽从getCid()获得的数字。
以下是一个摘要:

GsmCellLocation cellLocation = (GsmCellLocation)telm.getCellLocation();

new_cid = cellLocation.getCid() & 0xffff;
new_lac = cellLocation.getLac() & 0xffff;


希望能有所帮助

09-25 20:17