McLan
McLan

Reputation: 2688

How to compare the Wifi SSID to specific String

I am trying to compare the SSID of the connected wifi to the one I want it connect to. So I am using the following code:

WifiInfo wifiInfo = returnedWifiManager.getConnectionInfo();
String ssid = wifiInfo.getSSID().toString();
if (ssid.equalsIgnoreCase("MarkV")) {
   Toast.makeText(WalkitalkiMainActivity.this,
         "Connected to: " + ssid, Toast.LENGTH_SHORT).show();
}

when I debug, I find the right SSID name, but the Toast inside the if statement never execute. What is the problem ?

Upvotes: 1

Views: 888

Answers (1)

kmchmk
kmchmk

Reputation: 642

I just found the solution to this problem. The reason is ssid has double quotation marks around it. So you have to check like this.

if(ssid.equals("\"MarkV\"")){//or ssid.equalsIgnoreCase("\"MarkV\"")
    //Do
}
else{
    //Else do
}

Upvotes: 1

Related Questions