gpt4 book ai didi

android - 如何在android中获取LTE小区位置?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:39:23 26 4
gpt4 key购买 nike

我看到我们有 CDMACellLocation 和 GSMCellLocation 的类,但没有任何特定于 LTE 的类。我可以获得特定于我的电话服务上下文的 LTE 小区位置吗?谢谢!

最佳答案

您可以从 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));

在我的应用程序中,我注意到您只能获取列表中的第一个元素;我向您展示我的自定义类(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;
}
}

因此,如果被测设备不支持 LTE,您始终可以获取有关其连接的其他相关信息。希望您会发现它有用。

关于android - 如何在android中获取LTE小区位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16224684/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com