Android: Cellid Not Available On All Carriers?
Solution 1:
In order to find CellId, you should use 0xffff as bit-mask, NOT mod.
WRONG
new_cid = cellLocation.getCid() % 0xffff;
RIGHT
new_cid = cellLocation.getCid() & 0xffff;
Solution 2:
Try to use a PhoneStateListener as following:
First, create the listener.
publicPhoneStateListenerphoneStateListener=newPhoneStateListener() {
@OverridepublicvoidonCellLocationChanged(CellLocation location) {
StringBufferstr=newStringBuffer();
// GSMif (location instanceof GsmCellLocation) {
GsmCellLocationloc= (GsmCellLocation) location;
str.append("gsm ");
str.append(loc.getCid());
str.append(" ");
str.append(loc.getLac());
Log.d(TAG, str.toString());
}
}
};
And then register, on onCreate(), the listener as following:
telephonyManager = (TelephonyManager) getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CELL_LOCATION);
As stated on the documentation, the LISTEN_CELL_LOCATION requires you to add the following permission:
<uses-permissionandroid:name="android.permission.ACCESS_COARSE_LOCATION"/>
Solution 3:
I think this is due to the way the manufacturers have implemented the underlying kernel code on the device, not allowing you to access certain information.
Solution 4:
You need to use TelephonyManager
TelephonyManagertelephonyManager= (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
GsmCellLocationcellLocation= (GsmCellLocation) telephonyManager
.getCellLocation();
// Cell Id, LACintcellid= cellLocation.getCid();
intlac= cellLocation.getLac();
// MCCStringMCC= telephonyManager.getNetworkOperator();
intmcc= Integer.parseInt(MCC.substring(0, 3));
// Operator nameStringoperatoprName= telephonyManager.getNetworkOperatorName();
For permission you need to add followin in the Manifest.xml file
<uses-permissionandroid:name="android.permission.ACCESS_COARSE_LOCATION" />
Solution 5:
So you can try something like. I have got cell id and the location area code for GSM. But for UMTS, getCid () returns a big number for exple 33 166 248. So i add modulo operator (exple xXx.getCid() % 0xffff).
GsmCellLocationcellLocation= (GsmCellLocation)telm.getCellLocation();
new_cid = cellLocation.getCid() % 0xffff;
new_lac = cellLocation.getLac() % 0xffff;
Post a Comment for "Android: Cellid Not Available On All Carriers?"