如何获取3G网络的小区ID?

时间:2014-01-13 22:36:45

标签: java android 3g cellid

我收到了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

中授予了权限

1 个答案:

答案 0 :(得分:1)

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

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

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

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

希望有所帮助