1

我得到了错误的 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_LOCATIONACCESS_NETWORK_STATE的权限

4

1 回答 1

1

解决方案在以下线程中突出显示:Android:CellID 并非在所有运营商上都可用?

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

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

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

希望有帮助

于 2014-01-29T14:42:37.860 回答