Question

I'm having a strange problem with my code that I cannot figure out, although i'm sure it must be something simple. I've got an if statement in my code that compares the currently connected network name to a string. The problem i'm having is that it does not execute the code within the if statement even if the SSID matches the string, i've logged the current network name so i could check myself that it does match. I've named my network "1" in an attempte to simplify things when it first didn't work with the original network name.

if anyone's got any ideas, let me know :) thanks

code:

        ConnectivityManager connMgr = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
        mWifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

        WifiManager wifiMgr = (WifiManager) ActivityZoneControl.this.getSystemService(Context.WIFI_SERVICE);
        WifiInfo wifiConInfo = wifiMgr.getConnectionInfo();
        wifiName = wifiConInfo.getSSID()

        Log.i(debugLOG, wifiName);

        if (wifiName.equals("1")){
             //do something
        }

        else {
            // do something else
        }

Log:
log

Was it helpful?

Solution

Based on your log output, it seems your SSID string has quote characters included in it:

enter image description here

Consider using this test instead:

if (wifiName.equals("\"1\"")){
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top