get Configured Wifi By SSID - Android Wifi

Android examples for Wifi:Wifi SSID

Description

get Configured Wifi By SSID

Demo Code


//package com.java2s;

import android.content.Context;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import java.util.List;

public class Main {
    public static WifiConfiguration getConfiguredWifiBySSID(String SSID,
            Context ctx) {/* ww w .  j ava  2  s. c o m*/
        try {
            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