Java tutorial
//package com.java2s; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiConfiguration.AuthAlgorithm; import android.net.wifi.WifiConfiguration.KeyMgmt; public class Main { static final int SECURITY_NONE = 0; static final int SECURITY_WEP = 1; static final int SECURITY_PSK = 2; static final int SECURITY_EAP = 3; private static WifiConfiguration getConfig(int networkId, String ssid, String password, int mAccessPointSecurity) { WifiConfiguration config = new WifiConfiguration(); if (networkId == -1) { config.SSID = convertToQuotedString(ssid); } else { config.networkId = networkId; } switch (mAccessPointSecurity) { case SECURITY_NONE: config.allowedKeyManagement.set(KeyMgmt.NONE); break; case SECURITY_WEP: config.allowedKeyManagement.set(KeyMgmt.NONE); config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN); config.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED); if (password.length() != 0) { int length = password.length(); if ((length == 10 || length == 26 || length == 58) && password.matches("[0-9A-Fa-f]*")) { config.wepKeys[0] = password; } else { config.wepKeys[0] = '"' + password + '"'; } } break; case SECURITY_PSK: config.allowedKeyManagement.set(KeyMgmt.WPA_PSK); if (password.length() != 0) { if (password.matches("[0-9A-Fa-f]{64}")) { config.preSharedKey = password; } else { config.preSharedKey = '"' + password + '"'; } } break; case SECURITY_EAP: config.allowedKeyManagement.set(KeyMgmt.WPA_EAP); config.allowedKeyManagement.set(KeyMgmt.IEEE8021X); if (password.length() != 0) { if (password.matches("[0-9A-Fa-f]{64}")) { config.preSharedKey = password; } else { config.preSharedKey = '"' + password + '"'; } } break; default: return null; } return config; } static String convertToQuotedString(String string) { return "\"" + string + "\""; } }