How to get cell id for 3G network?

2.6k Views Asked by At

I am getting the the wrong cell Id for the 3G network, I got correct value of cell id for 2G, I don't understand where I am going wrong. Please help

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();

I have also given permissions in AndroiManifest.xml file ACCESS_COARSE_LOCATION, ACCESS_NETWORK_STATE

1

There are 1 best solutions below

0
On

Solutions are highlighted in the following thread: Android: CellID not available on all carriers?

In short you need to mask the number you get from getCid() when in 3G network with 0xffff. Following is a snippet:

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

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

Hope that helps