1

When my app starts I want to check if the device is connected to a specific wifi, my current code looks like this

private boolean haveNetwork() {
    boolean have_WIFI = false;

    ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
    NetworkInfo[] networkInfos = connectivityManager.getAllNetworkInfo();

    for (NetworkInfo info:networkInfos) {
        if (info.getTypeName().equalsIgnoreCase("WIFI" )) {
            if (info.isConnected())
                have_WIFI = true;
        }
    }
    return have_WIFI;
}

But it only checks if the device has any WIFI connection at all. How would I modify it to check for a specific WIFI SSID e.g. "Home"?

blue
  • 49
  • 7
  • Possible duplicate of [Get SSID when WIFI is connected](https://stackoverflow.com/questions/21391395/get-ssid-when-wifi-is-connected) – Murat Karagöz Oct 10 '19 at 08:15
  • Possible duplicate of [Finding SSID of a wireless network with Java](https://stackoverflow.com/questions/5378103/finding-ssid-of-a-wireless-network-with-java) – ivanjermakov Oct 10 '19 at 08:15

0 Answers0