SoFunction
Updated on 2025-04-04

Android determines whether wifi is 5G or 2.4G

I read this post at the beginning but couldn't find the answer. I'll reply for the sake of those who came later.

WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = ();

according to()Can tell if it is 5G

4 numbers should be returned

If the character starts with 2, it is 2.4G; if the character starts with 5, it is 5G.

It is best to use the first number to judge, rather than use all 4 numbers to judge, because the following has other meanings.

By the way, the above method is in the source code of 5.1. If you want to be compatible with 4.4, you must do this:

WifiInfo wifiInfo = ();
String tempSsidString = ();
if (tempSsidString != null && () > 2) {
wifiSsid = (1, () - 1);
List<ScanResult> scanResults=();
for(ScanResult scanResult:scanResults){
if((wifiSsid)){
;
break;
}
}
}

There are functions in wifiinfo that can determine whether it is 5G.

 /**
  * @hide
  * TODO: makes real freq boundaries
  */
 public boolean is5GHz() {
  return ScanResult.is5GHz(mFrequency);
 }

The above is what the editor introduces to you to determine whether wifi is 5G or 2.4G. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support for my website!