get Wifi Config By SSID - Android Wifi

Android examples for Wifi:Wifi SSID

Description

get Wifi Config By SSID

Demo Code


//package com.java2s;

import java.util.List;

import android.net.wifi.WifiConfiguration;

import android.net.wifi.WifiManager;

public class Main {

    private static WifiManager wifiManager;

    public static WifiConfiguration getWifiConfigBySSID(String ssid) {
        WifiConfiguration targetConfig = null;

        List<WifiConfiguration> configs = null;

        int loopNum = 0;
        while (loopNum++ < 15) {
            configs = wifiManager.getConfiguredNetworks();
            if (configs.size() == 0) {
                try {
                    Thread.sleep(200);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }//from  w w  w  .  j  a  v  a  2s.  c o m
                continue;
            } else {
                break;
            }
        }

        for (WifiConfiguration i : configs) {
            if (i.SSID != null && i.SSID.equals("\"" + ssid + "\"")) {
                targetConfig = i;
                // i.status = WifiConfiguration.Status.DISABLED;
                break;
            }
        }
        return targetConfig;
    }

    private static void sleep(int mm) {

        try {
            Thread.sleep(mm);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

Related Tutorials