Android Question Error while connecting to WiFi network

Harish Kumar Arya

Licensed User

I am new to Android development (and java too) and was trying to create a library which I can re-use in B4A for connecting to a WiFi network.

I followed the following link to create my library

Now the problem is, when i try to call the methods in the jar file (included as referenced libraries), my app gets disconnected from existing network but never connects to the network I pass the details of to the library. I haven't been able to figure out a way to test the methods in Eclipse and have been stuck with the problem for last 1 days. Any help will be much appreciated!

For simplicity here the code for the jar file:

public boolean ConnectToNetworkWEP(final BA ba, String networkSSID, String password )
try {
WifiConfiguration conf = new WifiConfiguration();
conf.SSID = "\"" + networkSSID + "\""; // Please note the quotes. String should contain SSID in quotes
conf.wepKeys[0] = password; //WEP password is in hex, we do not need to surround it with quotes.
conf.wepTxKeyIndex = 0;

WifiManager wifiManager = (WifiManager)ba.applicationContext.getSystemService(Context.WIFI_SERVICE);

List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
for( WifiConfiguration i : list ) {
if(i.SSID != null && i.SSID.equals("\"" + networkSSID + "\"")) {
wifiManager.enableNetwork(i.networkId, true);


//WiFi Connection success, return true
return true;
} catch (Exception ex) {

throw ex;