I am writing an application in android studio for android Pie.
I want to get wifi info.
@RequiresApi(api = Build.VERSION_CODES.S)
public String getData() {
String wifiDataTest;
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int frequency = wifiInfo.getFrequency();
int ipAddress = wifiInfo.getIpAddress();
int speed = wifiInfo.getLinkSpeed();
String ssid = wifiInfo.getSSID();
int wifiStandard = wifiInfo.getWifiStandard();
wifiDataTest = "Frequency [MHz]: " + frequency + "nIP address: " + ipAddress
+ "nSpeed [Mbps]: " + speed + "nSSID: " + ssid + "nWifi standard: " + wifiStandard;
return "WIFIn" + wifiDataTest;
}
With int wifiStandard = wifiInfo.getWifiStandard ();
shows me the error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.sensors, PID: 11040
java.lang.NoSuchMethodError: No virtual method getWifiStandard()I in class Landroid/net/wifi/WifiInfo; or its super classes (declaration of 'android.net.wifi.WifiInfo' appears in /system/framework/framework.jar)
I have not found information about such an error anywhere. Everything before getWifiStandard ();
worked fine.
2
Answers
You’re trying to run your app which contains the
getWifiStandard()
method that exists ONLY on Android 11 or up.Try this :
Situtation 1: It’s maybe you just reference to the function, missing ()
wrong example:
fun main(callback: () -> Unit) = callback
correct example:
fun main(callback: () -> Unit) = callback()
Situtation 2: the function is a Job, needed to be an Unit
wrong example:
fun main(callback: () -> Unit) =
MainScope().launch {
callback()
}
correct example:
fun main(callback: () -> Unit) {
MainScope().launch {
callback()
}
}
Situtation 3: just Google & God know ;))