Monday, August 29, 2011

Android, get cell id

Hello Everybody,

A quick snippet to get CORRECT cell id for Android:

public static int getCID(Context ctx) {
try {
TelephonyManager tm = (TelephonyManager)ctx.getSystemService(Context.TELEPHONY_SERVICE);
GsmCellLocation location = (GsmCellLocation)tm.getCellLocation();

int locationCellid = location.getCid();
int cellId = -1; // set to unknown location by default

if(cellId > 0) { // known location
cellId = locationCellid & 0xffff; // get only valuable bytes
}
return cellId;
} catch (Exception ignored) {}

return -1;
}


Happy location determination! (:

Best regards,
Yahor

0 comments:

Post a Comment