1

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

Ravi
  • 34,851
  • 21
  • 122
  • 183
Yogesh
  • 111
  • 1
  • 9

1 Answers1

1

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

Community
  • 1
  • 1
isaac.hazan
  • 3,772
  • 6
  • 46
  • 76