I would like to get cid from my mobile phone, I am currently using this code for this:
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 looking through some code examples and found this:
try {
updateLocation(getPaddedHex(cid, cellPadding), getPaddedHex(lac, 4),
getPaddedInt(mnc, 2), getPaddedInt(mcc, 3));
strResult = "Position updated!";
} catch (IOException e) {
strResult = "Error!\n" + e.getMessage();
}
Toast t = Toast.makeText(getApplicationContext(), strResult,
Toast.LENGTH_LONG);
t.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
t.show();}});
}
String getPaddedHex(int nr, int minLen) {
String str = Integer.toHexString(nr);
if (str != null) {
while (str.length() < minLen) {
str = "0" + str;
}
}
return str;
}
String getPaddedInt(int nr, int minLen) {
String str = Integer.toString(nr);
if (str != null) {
while (str.length() < minLen) {
str = "0" + str;
}
}
return str;
}
Is the number from GsmCellLocation correct or do I need to change the results as shown in the example? what is the difference? I know from the documentation that cid can be -1 (unknown) or 0xffff the maximum value, 0xffff for 2g or 3g networks?
source
share