如何在安卓设备上获取LTE基站位置?

6

我发现我们有CDMACellLocation和GSMCellLocation的类,但是没有专门针对LTE的。我怎样才能获得与我的电话服务上下文相关的LTE小区位置呢? 谢谢!


你只能在API 17中获取LTE信息。 - Hoan Nguyen
谢谢回复!我使用的是API 17。我想知道的是如何从TelephonyManager的getAllCellInfo()函数返回的arraylist中提取CellInfo。 - user1985703
3个回答

2
你可以从LTE连接中获取信息,特别是CellInfo列表中的实例。
MobileInfoRecognizer mobileInfoRecognizer = new MobileInfoRecognizer();
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
List<CellInfo> cellInfos = tm.getAllCellInfo();
additional_info = mobileInfoRecognizer.getCellInfo(cellInfos.get(0));

在我的应用程序中,我发现你只能获取列表中的第一个元素,以下是我的自定义类代码:

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

所以,如果被测试的设备不支持LTE,您仍然可以获取有关其连接的其他相关信息。希望您能发现它有用。

0

在这里要小心——虽然API可能提供单元格信息的接口,但它实际上取决于运营商。与可以作为其RADIUS输出的一部分提供粗略位置信息的CDMA不同,LTE因实现而异。只有LTE网络的“较低”级别知道您可能在哪里,而且这最多也是模糊的。如果不了解您的运营商基础设施、他们的MME工作方式等等,您可能会获得信息,但我不会相信它用于地理位置信息。

此外,这还取决于您的运营商如何轮询。根据设备配置文件的不同,您可能每分钟轮询一次、每五分钟轮询一次、每两个小时轮询一次。如果您正在漫游,您可能什么都得不到,因为没有关于值的良好标准。


-2

您可以通过迭代getAllCellInfo()返回的List列表,并检查CellInfo是否为CellInfoLte来进行操作。

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

1
这并没有回答问题。一旦您拥有了CellInfoLte对象,您如何获取位置信息? - DataDino

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接