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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.