Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get correct cell id and location area code in Android?

Tags:

android

I have found so much code that fetches cell-id and location area code and I use the code below to fetch cell-id and location area code.

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

int cid = cellLocation.getCid();
int lac = cellLocation.getLac();

The problem is, when I use an airtel-sim card it works fine and give cell-id =4331 and loc =610. But when I use a relience-sim card then it give wrong result cell-id =11541 and loc=18823. How might I resolve this?

like image 781
User10001 Avatar asked Jul 23 '13 07:07

User10001


People also ask

What is cell ID in mobile network?

A GSM Cell ID (CID) is a generally unique number used to identify each base transceiver station (BTS) or sector of a BTS within a location area code (LAC) if not within a GSM network.


1 Answers

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

like image 155
Amit Gajera Avatar answered Oct 28 '22 12:10

Amit Gajera