2013-04-25 61 views
5

我看到我们有CDMACellLocation和GSMCellLocation的类,但没有特定的LTE。我可以获得特定于我的电话服务环境的LTE小区位置吗? 谢谢!如何在android中获取LTE小区位置?

+0

您只能获得API 17中的LTE信息 – 2013-04-25 22:40:20

+0

感谢您的回复!我在API 17上。我想知道的是如何从TelephonyManager的getAllCellInfo()函数返回的arraylist中获取CellInfo的extarct。 – user1985703 2013-04-29 22:20:21

回答

-1

您可以通过getAllCellInfo(返回列表列表迭代),并检查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 2017-06-04 22:00:38

0

这里要小心 - 虽然API可用于小区信息提供一个接口,它真的取决于运营商。与可以提供课程位置信息作为其RADIUS输出的一部分的CDMA不同,LTE随实施而变化。只有LTE网络的“较低”级别知道你可能在哪里,而这最好是模糊的。如果不知道你的运营商的基础设施,他们的MME如何工作等,你可能会得到信息,但我不相信它的地理位置信息。

此外,这取决于您的运营商如何轮询。根据设备配置文件,您可能每分钟轮询一次,每五分钟轮询一次,每两小时轮询一次。如果你在漫游,你可能会得到任何东西,除了垃圾,因为没有很好的价值标准。

0

您可以从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,可以随时获得有关其连接的其他相关信息。希望你能找到它有用。