如何从网络获取波段信息?
How to get band information from network?
我想显示设备用于连接互联网的网络频率(频段)。
我找到了一个 app 可以在没有 root 的情况下执行此操作。
我不知道该怎么做。我可以使用以下代码获取 Rat 信息:
public String getNetworkClass(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = cm.getActiveNetworkInfo();
if (info == null || !info.isConnected())
return "-"; //not connected
if (info.getType() == ConnectivityManager.TYPE_WIFI)
return "WIFI";
if (info.getType() == ConnectivityManager.TYPE_MOBILE) {
int networkType = info.getSubtype();
Log.d("locknet", "networkType: " + networkType);
switch (networkType) {
case TelephonyManager.NETWORK_TYPE_GPRS:
case TelephonyManager.NETWORK_TYPE_EDGE:
case TelephonyManager.NETWORK_TYPE_CDMA:
case TelephonyManager.NETWORK_TYPE_1xRTT:
case TelephonyManager.NETWORK_TYPE_IDEN: //api<8 : replace by 11
return "2G";
case TelephonyManager.NETWORK_TYPE_UMTS:
case TelephonyManager.NETWORK_TYPE_EVDO_0:
case TelephonyManager.NETWORK_TYPE_EVDO_A:
case TelephonyManager.NETWORK_TYPE_HSDPA:
case TelephonyManager.NETWORK_TYPE_HSUPA:
case TelephonyManager.NETWORK_TYPE_HSPA:
case TelephonyManager.NETWORK_TYPE_EVDO_B: //api<9 : replace by 14
case TelephonyManager.NETWORK_TYPE_EHRPD: //api<11 : replace by 12
case TelephonyManager.NETWORK_TYPE_HSPAP: //api<13 : replace by 15
return "3G";
case TelephonyManager.NETWORK_TYPE_LTE: //api<11 : replace by 13
return "4G";
default:
return "UNKNOWN";
}
}
return "?";
}
我在 Internet 上进行了搜索,但一无所获。
请帮我获取乐队信息。我将非常感谢你。
可以获取ARFCN然后映射获取波段
使用下面的代码,然后自己做剩下的。
检查 this
TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
CellInfo ci = tm.getAllCellInfo().get(0) ; // Registered Cell Tower
if (ci instanceof CellInfoGsm) {
((CellInfoGsm)ci).getCellIdentity().getArfcn();
} else if (ci instanceof CellInfoWcdma) {
((CellInfoWcdma)ci).getCellIdentity().getUarfcn();
} else if (ci instanceof CellInfoLte) {
((CellInfoLte)ci).getCellIdentity().getEarfcn();
}
我想显示设备用于连接互联网的网络频率(频段)。 我找到了一个 app 可以在没有 root 的情况下执行此操作。 我不知道该怎么做。我可以使用以下代码获取 Rat 信息:
public String getNetworkClass(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = cm.getActiveNetworkInfo();
if (info == null || !info.isConnected())
return "-"; //not connected
if (info.getType() == ConnectivityManager.TYPE_WIFI)
return "WIFI";
if (info.getType() == ConnectivityManager.TYPE_MOBILE) {
int networkType = info.getSubtype();
Log.d("locknet", "networkType: " + networkType);
switch (networkType) {
case TelephonyManager.NETWORK_TYPE_GPRS:
case TelephonyManager.NETWORK_TYPE_EDGE:
case TelephonyManager.NETWORK_TYPE_CDMA:
case TelephonyManager.NETWORK_TYPE_1xRTT:
case TelephonyManager.NETWORK_TYPE_IDEN: //api<8 : replace by 11
return "2G";
case TelephonyManager.NETWORK_TYPE_UMTS:
case TelephonyManager.NETWORK_TYPE_EVDO_0:
case TelephonyManager.NETWORK_TYPE_EVDO_A:
case TelephonyManager.NETWORK_TYPE_HSDPA:
case TelephonyManager.NETWORK_TYPE_HSUPA:
case TelephonyManager.NETWORK_TYPE_HSPA:
case TelephonyManager.NETWORK_TYPE_EVDO_B: //api<9 : replace by 14
case TelephonyManager.NETWORK_TYPE_EHRPD: //api<11 : replace by 12
case TelephonyManager.NETWORK_TYPE_HSPAP: //api<13 : replace by 15
return "3G";
case TelephonyManager.NETWORK_TYPE_LTE: //api<11 : replace by 13
return "4G";
default:
return "UNKNOWN";
}
}
return "?";
}
我在 Internet 上进行了搜索,但一无所获。
请帮我获取乐队信息。我将非常感谢你。
可以获取ARFCN然后映射获取波段
使用下面的代码,然后自己做剩下的。 检查 this
TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
CellInfo ci = tm.getAllCellInfo().get(0) ; // Registered Cell Tower
if (ci instanceof CellInfoGsm) {
((CellInfoGsm)ci).getCellIdentity().getArfcn();
} else if (ci instanceof CellInfoWcdma) {
((CellInfoWcdma)ci).getCellIdentity().getUarfcn();
} else if (ci instanceof CellInfoLte) {
((CellInfoLte)ci).getCellIdentity().getEarfcn();
}