如何查看当前连接的网络是否为WIFI 5G?

How check if current network connected is WIFI 5G?

我用过this approach to check type of current connected network and works fine, except when is connected to WIFI 5G. How know if WIFI network connected is 5G? i only found how check if device supports WIFI 5G。提前致谢。

根据WIFI frequency确定可能的解决方案,例如:

private static boolean is24GHzWifi(int frequency) {
        return frequency > 2400 && frequency < 2500;
    }

    private static boolean is5GHzWifi(int frequency) {
        return frequency > 4900 && frequency < 5900;
    }
    
// ...

if (info.getType() == ConnectivityManager.TYPE_WIFI) {

            WifiManager wifiMgr = (WifiManager) getContext().getSystemService(context.WIFI_SERVICE);
            WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
            int frequency = wifiInfo.getFrequency();

            if (is24GHzWifi(frequency))
                return "WIFI 2.4G";
            else if (is5GHzWifi(frequency))
                return "WIFI 5G";
            else
                return "WIFI";
  }

参考:Android judge whether wifi is 2.4G or 5G