Code example for WifiManager

Methods: addNetworkenableNetworkisWifiEnabledsetWifiEnabled

0
 
			private void connectToServer() { 
				// TODO Auto-generated method stub 
				WifiManager mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
 
				if (!mWifiManager.isWifiEnabled()) {
					mWifiManager.setWifiEnabled(true);
 
				} 
 
				WifiConfiguration netConfig = new WifiConfiguration();
				netConfig.SSID = "\"Bomb\"";
				netConfig.preSharedKey = "\"bombplus\"";
				netConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
			    netConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
			    netConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
			    netConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
			    netConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
			    netConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
			    netConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
			    netConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); 
 
				if (mWifiManager.enableNetwork(
						mWifiManager.addNetwork(netConfig), true)) {
					et_output.setText("[Hotspot] get\n");
				} else { 
					et_output.setText("no [Hotspot]\n");
				} 
			}