2013-04-25 67 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,可以隨時獲得有關其連接的其他相關信息。希望你能找到它有用。