I would like to get the cid from my cell phone , I am currently using this code to do that :
GsmCellLocation gsmLocation = (GsmCellLocation)telephonyManager.getCellLocation();
int Cid = gsmLocation.getCid();
Log.e("#############","current cid is: "+Cid);
int lac = gsmLocation.getLac();
Log.e("#############","current lac is: "+lac);
this returns something like 301 or 6061.
I was browsing some example codes and found this :
/**
* Seems that cid and lac shall be in hex. Cid should be padded with zero's
* to 8 numbers if UMTS (3G) cell, otherwise to 4 numbers. Mcc padded to 3
* numbers. Mnc padded to 2 numbers.
*/
try {
// Update the current location
updateLocation(getPaddedHex(cid, cellPadding), getPaddedHex(lac, 4),
getPaddedInt(mnc, 2), getPaddedInt(mcc, 3));
strResult = "Position updated!";
} catch (IOException e) {
strResult = "Error!\n" + e.getMessage();
}
// Show an info Toast with the results of the updateLocation
// call.
Toast t = Toast.makeText(getApplicationContext(), strResult,
Toast.LENGTH_LONG);
t.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
t.show();}});
}
/**
* Convert an int to an hex String and pad with 0's up to minLen.
*/
String getPaddedHex(int nr, int minLen) {
String str = Integer.toHexString(nr);
if (str != null) {
while (str.length() < minLen) {
str = "0" + str;
}
}
return str;
}
/**
* Convert an int to String and pad with 0's up to minLen.
*/
String getPaddedInt(int nr, int minLen) {
String str = Integer.toString(nr);
if (str != null) {
while (str.length() < minLen) {
str = "0" + str;
}
}
return str;
}
Isn’t the number from the GsmCellLocation correct or I need to alter the results as shown in the example?
what is the difference? I know from the documentation that the cid could be -1 (unknown) or 0xffff max value, the 0xffff is for 2g or 3g networks?
That code doesn’t really alter the numbers. It’s only displaying them differently as hex or with more zeros on the left.