List of usage examples for android.net.wifi WifiConfiguration WifiConfiguration
public WifiConfiguration()
From source file:org.protocoderrunner.apprunner.api.PNetwork.java
@ProtocoderScript @APIMethod(description = "Connect to a given Wifi network with a given 'wpa', 'wep', 'open' type and a password", example = "") @APIParam(params = { "ssidName", "type", "password" }) public void connectWifi(String networkSSID, String type, String networkPass) { WifiConfiguration conf = new WifiConfiguration(); conf.SSID = "\"" + networkSSID + "\""; // Please note the quotes. String // should contain ssid in quotes if (type.equals("wep")) { // wep//w w w. j a v a 2s. c om conf.wepKeys[0] = "\"" + networkPass + "\""; conf.wepTxKeyIndex = 0; conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40); } else if (type.equals("wpa")) { // wpa conf.preSharedKey = "\"" + networkPass + "\""; } else if (type.equals("open")) { // open conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); } WifiManager wifiManager = (WifiManager) a.get().getSystemService(Context.WIFI_SERVICE); wifiManager.addNetwork(conf); List<WifiConfiguration> list = wifiManager.getConfiguredNetworks(); for (WifiConfiguration i : list) { if (i.SSID != null && i.SSID.equals("\"" + networkSSID + "\"")) { wifiManager.disconnect(); wifiManager.enableNetwork(i.networkId, true); wifiManager.reconnect(); break; } } }
From source file:org.protocoderrunner.apprunner.api.PNetwork.java
@ProtocoderScript @APIMethod(description = "Enable/Disable a Wifi access point", example = "") @APIParam(params = { "boolean, apName" }) public void wifiAP(boolean enabled, String wifiName) { WifiManager wifi = (WifiManager) a.get().getSystemService(a.get().WIFI_SERVICE); Method[] wmMethods = wifi.getClass().getDeclaredMethods(); Log.d(TAG, "enableMobileAP methods " + wmMethods.length); for (Method method : wmMethods) { Log.d(TAG, "enableMobileAP method.getName() " + method.getName()); if (method.getName().equals("setWifiApEnabled")) { WifiConfiguration netConfig = new WifiConfiguration(); netConfig.SSID = wifiName;/*from ww w . j a va 2 s. c o m*/ netConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN); netConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN); netConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA); netConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); // try { //MLog.d(TAG, "enableMobileAP try: "); method.invoke(wifi, netConfig, enabled); if (netConfig.wepKeys != null && netConfig.wepKeys.length >= 1) { Log.d(TAG, "enableMobileAP key : " + netConfig.wepKeys[0]); } //MLog.d(TAG, "enableMobileAP enabled: "); mIsWifiAPEnabled = enabled; } catch (Exception e) { //MLog.e(TAG, "enableMobileAP failed: ", e); } } } }