connect To ssid - Android android.net.wifi

Android examples for android.net.wifi:Wifi SSID

Description

connect To ssid

Demo Code

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

public class Main{

    public static void connectTo(Context context, String ssid) {
        WifiManager wifiManager = (WifiManager) context
                .getSystemService(Context.WIFI_SERVICE);
        WifiConfiguration conf = new WifiConfiguration();
        conf.SSID = ssid;// ww w  .  j  a v  a 2 s.com
        conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
        int networkId = wifiManager.addNetwork(conf);
        if (networkId != -1) {
            wifiManager.enableNetwork(networkId, true);
        }
    }

}

Related Tutorials