2
votes

I tried to check that mobile is connecting to required wifi are not? So, I use this code.

(wifiInfo.getSSID().equals("WiredSSID"))

but it doesn't work. When I try to make toast name, it still shows "WiredSSID". So, I don't know what point is wrong.

Moreover, how can I connect to Captive Portal Wifi Automatically. I use the code from How do I connect to a specific Wi-Fi network in Android programmatically?

make it to OPEN type (conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);) and put it in OnCreate function, but it cant work. I don't know that I should change network type or not? Please help me, thank you

2

2 Answers

1
votes

You can try the below code snippet to check for available wifi networks and get connected to a specified wifi network

         List<ScanResult> wifiScanList = wifi.getScanResults();
         wifis = new String[wifiScanList.size()];

         for(int i = 0; i < wifiScanList.size(); i++){
            wifis[i] = ((wifiScanList.get(i)).SSID);                

            if(wifis[i].equals("WiredSSID")) {

                 WifiConfiguration wifiConfig = new WifiConfiguration();
                 wifiConfig.SSID = String.format("\"%s\"", wifis[i]);
                 wifiConfig.preSharedKey = String.format("\"%s\"", "password");

                 WifiManager wifiManager = (WifiManager)getSystemService(WIFI_SERVICE);
                 //remember id
                 int netId = wifiManager.addNetwork(wifiConfig);
                 wifiManager.disconnect();
                 wifiManager.enableNetwork(netId, true);
                 wifiManager.reconnect();
             }
         }
0
votes
String networkSSID = "WiredSSID";
(wifiInfo.getSSID().equals("\"" + networkSSID + "\""))

Please note the quotes. String should contain ssid in quotes.