getAllCellInfo returns null for 2G sims - android

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.

Related

How to check if SIM is active?

I have a use case where I need to check whether a SIM is active in the device. In older devices, I can use TelephonyManager to get the SIM state and check whether it is SIM_STATE_READY. The issue is with API 22 and above.
Using SubscriptionManager, when I call getActiveSubscriptionInfoList, it sends me details about the SIMs present, even if I have turned them off. I went through the documentation of SubscriptionManager but couldn't find a similar method to check SIM's state. Using TelephonyManager in API above 22 gives information only about the default SIM, I would like to know this about both slots in dual SIM phones. Also, I found an overloaded variant of getSimState in TelephonyManager which does accept the slot as a parameter, but that got introduced in API 26. I would like a solution that will work in APIs 22-25 as well.
Is there a way I could identify that even though the SIM is present in the device, it isn't active?
You can check by like this if Device is dual sim
SubscriptionManager sManager = (SubscriptionManager) context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
SubscriptionInfo infoSim1 = sManager.getActiveSubscriptionInfoForSimSlotIndex(0);
SubscriptionInfo infoSim2 = sManager.getActiveSubscriptionInfoForSimSlotIndex(1);
int count = 0;
if (infoSim1 != null ) {
count++;
}
if (infoSim2 != null){
count++;
}
count decides that how many sims are active.
OR
You can get the count then check one by one
sManager.getActiveSubscriptionInfoCount()
Hope it's work.
TelephonyManager manager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
if (manager.getPhoneCount() == 2) {
// Dual sim
}
Examples here

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;
}

How to get IMEI of all SIM cards by using Lollipop MR1 Multiple SIM support (via SubscriptionManager)?

As announced for Lollipop MR1, SubscriptionManager and its SubscriptionInfo provide lots of information about all (active) SIMs, but I'm missing their IMEIs.
I get info about SIMs like this:
SubscriptionManager sm = SubscriptionManager.from(context);
List<SubscriptionInfo> sil = sm.getActiveSubscriptionInfoList();
if (sil != null) {
for (SubscriptionInfo subInfo : sil) {
Log.d(TAG, "SubInfo:" + subInfo);
}
} else {
Log.d(TAG, "SubInfo: list is null");
}
Am I missing something or can we still only get the IMEI (only of the 1st SIM card) via telephonyManager.getDeviceId()?
The method
public String getDeviceId(int slotId)
is available under TelephonyManager in API 23. slotId is just a number from 0 to the number of SIMs - 1.
In API 22, the same method exists but is hidden. You need to use reflection to call it.
The IMEI is used to identify the device, not the SIMs.So yes, you can only get the IMEI through telephonyManager.getDeviceId().
UPDATE: So it turns out I was wrong and a device can have an IMEI for each SIM card. I've found this answer in StackOverflow that can help you.
Android : Check whether the phone is dual SIM

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