Reputation: 109
I see that we have classes for CDMACellLocation and GSMCellLocation, but there is nothing specific for LTE. Can can I get the LTE cell location specific to my telephony service context? Thanks!
Upvotes: 6
Views: 7923
Reputation: 714
you could take info from LTE connection, with a specific cast on instances belonging to CellInfo's list.
MobileInfoRecognizer mobileInfoRecognizer = new MobileInfoRecognizer();
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
List<CellInfo> cellInfos = tm.getAllCellInfo();
additional_info = mobileInfoRecognizer.getCellInfo(cellInfos.get(0));
In my application I noticed that you can take only the first element in your list; I show you my custom class:
public class MobileInfoRecognizer {
public String getCellInfo(CellInfo cellInfo) {
String additional_info;
if (cellInfo instanceof CellInfoGsm) {
CellInfoGsm cellInfoGsm = (CellInfoGsm) cellInfo;
CellIdentityGsm cellIdentityGsm = cellInfoGsm.getCellIdentity();
additional_info = "cell identity " + cellIdentityGsm.getCid() + "\n"
+ "Mobile country code " + cellIdentityGsm.getMcc() + "\n"
+ "Mobile network code " + cellIdentityGsm.getMnc() + "\n"
+ "local area " + cellIdentityGsm.getLac() + "\n";
} else if (cellInfo instanceof CellInfoLte) {
CellInfoLte cellInfoLte = (CellInfoLte) cellInfo;
CellIdentityLte cellIdentityLte = cellInfoLte.getCellIdentity();
additional_info = "cell identity " + cellIdentityLte.getCi() + "\n"
+ "Mobile country code " + cellIdentityLte.getMcc() + "\n"
+ "Mobile network code " + cellIdentityLte.getMnc() + "\n"
+ "physical cell " + cellIdentityLte.getPci() + "\n"
+ "Tracking area code " + cellIdentityLte.getTac() + "\n";
} else if (cellInfo instanceof CellInfoWcdma){
CellInfoWcdma cellInfoWcdma = (CellInfoWcdma) cellInfo;
CellIdentityWcdma cellIdentityWcdma = cellInfoWcdma.getCellIdentity();
additional_info = "cell identity " + cellIdentityWcdma.getCid() + "\n"
+ "Mobile country code " + cellIdentityWcdma.getMcc() + "\n"
+ "Mobile network code " + cellIdentityWcdma.getMnc() + "\n"
+ "local area " + cellIdentityWcdma.getLac() + "\n";
}
return additional_info;
}
}
So, if device under test doesn't support LTE, you can always obtain other related information about its connection. Hope you can find it useful.
Upvotes: 2
Reputation: 632
Be careful here -- Though the API may provide an interface for cell info, it really depends on the carrier. Unlike CDMA which could provide course location information as part of its RADIUS output, LTE varies by implementation. Only the "lower" levels of the LTE network know where you might be, and that is fuzzy at best. Without knowing your carrier's infrastructure, how their MME works etc, you may get information, but I'd not trust it for geo-location information.
Furthermore, it depends on how your carrier polls. Depending on the device profile, you might be polled once a minute, once every five minutes, once every two hours. If you're roaming, you may get nothing but garbage as there's no nice standard for values.
Upvotes: 0
Reputation: 18151
You can iterate through the list List returned by getAllCellInfo () and check if the CellInfo is a CellInfoLte or not by
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
List<CellInfo> cellInfoList = tm.getAllCellInfo();
for (CellInfo cellInfo : cellInfoList)
{
if (cellInfo instanceof CellInfoLte)
{
// cast to CellInfoLte and call all the CellInfoLte methods you need
}
}
Upvotes: -2