get Configured Wifi By SSID - Android android.net.wifi

Android examples for android.net.wifi:Wifi SSID

Description

get Configured Wifi By SSID

Demo Code

import java.util.List;

import android.content.Context;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;

public class Main {

  public static WifiConfiguration getConfiguredWifiBySSID(String SSID, Context ctx) {
    try {/*from   w  ww  .  j  av  a 2  s.  co  m*/
      WifiManager mainWifi = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE);

      List<WifiConfiguration> wifiConfigurations;

      wifiConfigurations = mainWifi.getConfiguredNetworks();
      for (int i = 0; i < wifiConfigurations.size(); i++) {
        if (wifiConfigurations.get(i) != null && wifiConfigurations.get(i).SSID != null
            && wifiConfigurations.get(i).SSID.equalsIgnoreCase(SSID))
          return wifiConfigurations.get(i);
      }
    } catch (Exception e) {
    }
    return null;
  }

}

Related Tutorials