gpt4 book ai didi

java - 如何获取 3G 网络的小区 ID?

转载 作者:行者123 更新时间:2023-11-30 03:10:23 25 4
gpt4 key购买 nike

我得到错误的 3G 网络小区 ID,我得到正确的 2G 小区 ID 值,我不明白我哪里出错了。请帮忙

TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
GsmCellLocation cellLocation = (GsmCellLocation) telephonyManager
.getCellLocation();

//Cell Id, LAC
int cid = cellLocation.getCid();
int lac = cellLocation.getLac();

//MCC
String MCC =telephonyManager.getNetworkOperator();
int mcc = Integer.parseInt(MCC.substring(0, 3));
String mcc1 = String.valueOf(mcc);

//Operator name
String operatoprName = telephonyManager.getNetworkOperatorName();

我还在 AndroiManifest.xml 文件 ACCESS_COARSE_LOCATION 中授予了权限,ACCESS_NETWORK_STATE

最佳答案

解决方案在以下线程中突出显示:Android: CellID not available on all carriers?

简而言之,在 3G 网络中,您需要使用 0xffff 屏蔽从 getCid() 获得的号码。以下是一个 fragment :

GsmCellLocation cellLocation = (GsmCellLocation)telm.getCellLocation();

new_cid = cellLocation.getCid() & 0xffff;
new_lac = cellLocation.getLac() & 0xffff;

希望对你有帮助

关于java - 如何获取 3G 网络的小区 ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21102785/

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