如何从网络获取频段信息?

时间:2019-06-21 09:13:10

标签: android network-programming

我想显示设备用于连接互联网的网络频率(频段)。 我发现一个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 "?";
    }

我在互联网上搜索,但一无所获。

请帮助我获取乐队信息。我将非常感谢您。

1 个答案:

答案 0 :(得分:0)

您可以获取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();
}
相关问题