I'm looking for how to connect to WIFI AP and found this.
How do I connect to a specific Wi-Fi network in Android programmatically?
And With the code above, I made up the below code.
public void connect_dhcp()
{
String sSSID = "TESTAP";
String sPassword = "12341234";
WifiConfiguration wfc = new WifiConfiguration();
wfc.SSID = "\"".concat(sSSID).concat("\"");
wfc.status = WifiConfiguration.Status.DISABLED;
wfc.priority = 40;
wfc.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
wfc.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
wfc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
wfc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
wfc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
wfc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
wfc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104);
wfc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
wfc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
wfc.preSharedKey = "\"".concat(sPassword).concat("\"");
WifiManager wfMgr = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE);
int networkId = wfMgr.addNetwork(wfc);
if (networkId != -1) {
Log.d("SCAN", "Success");
wfMgr.enableNetwork(networkId, true);
}
}
But I also need to connect with static ip.
Can anyone help me connect to WIFI AP with static ip?