I’m trying to find if scanResult is the currently connected wifi network.
here is my code
public boolean IsCurrentConnectedWifi(ScanResult scanResult)
{
WifiManager mainWifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo currentWifi = mainWifi.getConnectionInfo();
if(currentWifi != null)
{
if(currentWifi.getSSID() != null)
{
if(currentWifi.getSSID() == scanResult.SSID)
return true;
}
}
return false;
}
I have no problem with getting scanresult.
I’m always getting the currentWifi null.
Where am I doing wrong or is there any alternative method to do this?
Most probably you have already found answer:
currentWifi.getSSID()is quoted in most cases wherescanResult.SSIDis not (and of course you must not use==on strings :)).Try something like this, it returns current
SSIDornull:also permissions are required:
StringUtilis not a standard Android class, so you can useTextUtilsinstead. The code then looks like this: