Just call this function by passing the login and password into String plus this function only works for Wifi WPA_PSK and WPA2_psk
public void Connection(String ssid, String password){
WifiConfiguration wfc = new WifiConfiguration();
wfc.SSID = "\"".concat(ssid).concat("\"");
wfc.status = WifiConfiguration.Status.DISABLED;
wfc.priority = 40;
wfc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
wfc.preSharedKey = "\"".concat(password).concat("\"");
WifiManager wfMgr = (WifiManager) mGap.getSystemService(Context.WIFI_SERVICE);
int networkId = wfMgr.addNetwork(wfc);
if (networkId != -1) {
// success, can call wfMgr.enableNetwork(networkId, true) to connect
wfMgr.enableNetwork(networkId, true);
}
}