Neighbor cells have -1 for CID and LAC - android

In Android, I try to get the neighbor cells information. I use the following piece of code
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
List<NeighboringCellInfo> neighborCells = telephonyManager.getNeighboringCellInfo();
if (neighborCells == null) {
Log.d("cells", "Neighbor cells is null");
} else {
for (NeighboringCellInfo cell : neighborCells) {
Log.d("cells", cell.getCid()+"-"+cell.getLac()+" "+(-113+cell.getRssi()*2)+"dB");
}
}
Using logcat, I get the following output
D/cells ( 7668): Neighbor cell: -1--1 -81dB
D/cells ( 7668): Neighbor cell: -1--1 -113dB
D/cells ( 7668): Neighbor cell: -1--1 -113dB
Do you know why ? Is it related with the hardware ? With another phone, I get always "Neighbor cells is null"
Thank you

Check if youu are using a CDMA phone or a GSM phone. NeighboringCellInfo only works for a GSM phone since you don't have neighboring towers for CDMA. CDMA has a globally unique network id.
TelephonyManager mManager_;
mManager_ = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
if(mManager_.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA){
//CDMA PHONE
}
else if(mManager_.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM){
//GSM PHONE
}
uses permission: android.permission.ACCESS_NETWORK_STATE
hope this helps!

Ok I found the solution, I needed to enable the option "use only 2G networks". What would be nice is the possibility to enable that option from my application. It seems it is not possible but strange because this application does it...
Does somebody knows why I have more information with 2G cells than 3G ?

Related

Is there a smooth way to get the eNB id of a cell tower in Android Studio?

im new to android app development and currently trying to get the eNB in Android Studio with Kotlin. Im aware of this solution: How to get eNB id of LTE on Android Studio (TelephonyManager)
However, if I try to implement this, my app just crashes and I get no feedback. Is there anything special you need to keep in mind when setting up your app to get mobile cell data?
Thank you!
Just initialize a TelephonyManager from the Telephony_Service and by filtering for the different mobile net standards like UMTS (3G), LTE (4G) or NR (5G) and using the "getallCellInfo Method, you can get all relevant information from the current cell your phone is connected with. Here is the code:
val tm = getSystemService(TELEPHONY_SERVICE) as TelephonyManager
val cellInfo = tm.allCellInfo
if(cellInfo != null){
for(info in cellInfo){
if(info is CellInfoLte){
val identityLte = info.cellIdentity
val operator = identityLte.operatorAlphaLong.toString()
// get more Information like mcc, mnc, pci, tac, ... //
}
}
}

get right cellID in android network?

i have been working to find right CellID in android network. i am trying to search tutorial, i found the solution something like this:
telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
cellLocation = (GsmCellLocation) telephonyManager.getCellLocation();
Then to access CellID, use this code:
cellLocation.getCid() % 0xffff
When i run the apps, i got an ID number. But, the problem is different IDCELL with G Nettrack apps as reference. Then, the CELLID doesn't match with original data.
Please help! Thanks
I think you are doing wrong calculation.
For GSM network: it should be '&' instead of '%'
GsmCellLocation loc = (GsmCellLocation) tm.getCellLocation();
if (loc != null)
{
long cellID = loc.getCid() & 0xffff;
}
For 4g/LTE cellid's, there is a good article written here.follow that.

getAllCellInfo returns null for 2G sims

If i use getAllCellInfo() in a device which contains 2G sim it is returning null (note: API Level: 21). I even tried getNeighboringCellInfo() it is returning an empty List<NeighboringCellInfo>
TelephonyManager telephonyManager = (TelephonyManager)mContext.getSystemService( Context.TELEPHONY_SERVICE );
if (Build.VERSION.SDK_INT>= Build.VERSION_CODES.JELLY_BEAN_MR2) {
List<CellInfo> cellInfos = telephonyManager.getAllCellInfo();
if(cellInfos==null){
List<NeighboringCellInfo> neighboringCellInfos = telephonyManager.getNeighboringCellInfo();
CellLocation cellLocation = telephonyManager.getCellLocation();
}
}
Note: I have required permissions android.permission.ACCESS_COARSE_LOCATION for getAllCellInfo in my manifest file
Sorry for posting this inappropriate question. I found that, the issue i mentioned above is not because i am using a 2G sim, it is because I dont have sim in SIM1 Slot. When I am using this code with a 3G sim(Slot 1) and 2G(Slot 2) it worked as I expected then I disabled Slot1 to check for 2G and I got the above problem.
After a while of testing I enabled SIM1 and changed it to 2G, now I am getting expected results. I am writing so that it can help others. Sorry for my English.

How to display all available cells on a galaxy nexus (4.3)

My employer gave me a femto-cell and currently i am trying to figure if my galaxy-nexus can access the femtocell. As i cant force my phone to use this specific cell and it automatically always uses just available macro-cells, i have trouble to figure if the femtocell is present at all.
Here is what i tried so far. But it always returns null, which means in android-docs that my device isnt capable of using CellInfo-methods.
telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
List<CellInfo> cellInfo = telephonyManager.getAllCellInfo(); // returns null
List<NeighboringCellInfo> cellInfo = telephonyManager.getNeighboringCellInfo(); // returns null
then
telephonyManager.getPhoneType(); // returns PHONE_TYPE_GSM
aswell i found this quote in another post:
Conclusion: getting information about nearby cells on Android is
pretty messy business at the moment. You may need to use a combination
of all three methods to get the information you want, and even that
way, some things may be inaccessible.
What might be the third option? Does anyone have a conclusion for a galaxy nexus?
Does anyone have another idea how i could detect the availabilty of the femto_cell? it is driving me mad :/
Use CellLocation to find the cell id(base station ID).
Try something like this
TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
CellLocation cl = tm.getCellLocation();
GsmCellLocation gsmLoc;
CdmaCellLocation cdmaLoc;
try {
gsmLoc = (GsmCellLocation) cl;
System.out.println("Cell id " + gsmLoc.getCid());
System.out.println("Lac - " + gsmLoc.getLac());
System.out.println("Psc - " + gsmLoc.getPsc());
} catch (ClassCastException e) {
cdmaLoc = (CdmaCellLocation) cl;
System.out.println("Base station ID - "+ cdmaLoc.getBaseStationId());
System.out.println("Base station Latitude - "+ cdmaLoc.getBaseStationLatitude());
System.out.println("Network Id - "+ cdmaLoc.getNetworkId());
System.out.println("System ID -"+ cdmaLoc.getSystemId());
}
System.out.println("Operator Name - "+ tm.getNetworkOperatorName());
I tested using Verizon's network extender and the operator name returned is "Network Extender".
I used Samsung Note 3. A "home" icon displayed on the status bar When connected to femto cell.
Especially on older phones getAllCellInfo() is not always supported. Try to use the old methods for retrieving cell information of the connected base station:
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
GsmCellLocation cellLocation = (GsmCellLocation) telephonyManager.getCellLocation();
int cellid = cellLocation.getCid();
...
Unfortunately, there is no way to get the neighboring cells on a Samsung device. In my experience you get best results (and working getAllCellInfo()) with current LG phones.

Android IMEI Confusion for "Dual Simcard Devices"

I am using below code to get the IMEI of the Android devices,
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
IMEI = tm.getDeviceId();
It is fine for the devices having a single sim active. If we apply the same code for the devices having two sim cards, then how can I get the DeviceID and tell whether I got SIM1 Id or SIM2 Id?
IMEI number should be associated with the phone and not with the sim, so also in dual sim devices you should have only one IMEI number.
"The IMEI is only used for identifying the device" [...] "Instead, the subscriber is identified by transmission of an IMSI number, which is stored on a SIM card" - ref: Wikipedia
EDIT:
Check the source code, maybe you can find some hint: Source of Settings app
Here a snippet of the "IMEI" part:
// NOTE "imei" is the "Device ID" since it represents
// the IMEI in GSM and the MEID in CDMA
if (mPhone.getPhoneName().equals("CDMA")) {
setSummaryText(KEY_MEID_NUMBER, mPhone.getMeid());
setSummaryText(KEY_MIN_NUMBER, mPhone.getCdmaMin());
if (getResources().getBoolean(R.bool.config_msid_enable)) {
findPreference(KEY_MIN_NUMBER).setTitle(R.string.status_msid_number);
}
setSummaryText(KEY_PRL_VERSION, mPhone.getCdmaPrlVersion());
removePreferenceFromScreen(KEY_IMEI_SV);
if (mPhone.getLteOnCdmaMode() == PhoneConstants.LTE_ON_CDMA_TRUE) {
// Show ICC ID and IMEI for LTE device
setSummaryText(KEY_ICC_ID, mPhone.getIccSerialNumber());
setSummaryText(KEY_IMEI, mPhone.getImei());
} else {
// device is not GSM/UMTS, do not display GSM/UMTS features
// check Null in case no specified preference in overlay xml
removePreferenceFromScreen(KEY_IMEI);
removePreferenceFromScreen(KEY_ICC_ID);
}
} else {
setSummaryText(KEY_IMEI, mPhone.getDeviceId());
setSummaryText(KEY_IMEI_SV,
((TelephonyManager) getSystemService(TELEPHONY_SERVICE))
.getDeviceSoftwareVersion());
// device is not CDMA, do not display CDMA features
// check Null in case no specified preference in overlay xml
removePreferenceFromScreen(KEY_PRL_VERSION);
removePreferenceFromScreen(KEY_MEID_NUMBER);
removePreferenceFromScreen(KEY_MIN_NUMBER);
removePreferenceFromScreen(KEY_ICC_ID);
// only show area info when SIM country is Brazil
if ("br".equals(mTelephonyManager.getSimCountryIso())) {
mShowLatestAreaInfo = true;
}
}
In Dual Sim Devices, they have two IMEI Numbers for each SIM Slots. both are static. First IMEI No. is for First Slot and Second No. is for Second Slot.

Categories

Resources