get right cellID in android network? - android

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.

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, ... //
}
}
}

TelephonyManager returns null for IMEI number: what can cause this?

I'm working on an Android app and am getting null back for the IMEI number when using TelophonyManager. This is happening on several Huawei phones. (All of them are Ascend Y530s).
The phones all have sim cards and otherwise seem to be operating normally. I was under the impression that only a broken phone would return null IMEI. Clearly this is not the case..
Questions. What exactly is this IMEI number - i.e where is it stored on the device? And what does it mean when a seemingly fine phone returns its value as null?
EDIT
I should mention that the IMEI number is not always null. About half the time it seems to be valid (though this is very difficult to measure since we have 5 phones returning null IMEI numbers \ sometimes )
After your comment, to get unique device id for the survey app, i would suggest you to use Settings.Secure.ANDROID_ID as your unique id.
String myAndroidDeviceId = Secure.getString(getApplicationContext().getContentResolver(), Secure.ANDROID_ID);
Or you can use both as
public String getUniqueID(){
String myAndroidDeviceId = "";
TelephonyManager mTelephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
if (mTelephony.getDeviceId() != null){
myAndroidDeviceId = mTelephony.getDeviceId();
}else{
myAndroidDeviceId = Secure.getString(getApplicationContext().getContentResolver(), Secure.ANDROID_ID);
}
return myAndroidDeviceId;
}

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.

Neighbor cells have -1 for CID and LAC

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 ?

Categories

Resources