Android Question Error while connecting to WiFi network

Harish Kumar Arya

Member
Licensed User
Longtime User
Hi,

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
http://stackoverflow.com/questions/...ific-wifi-network-in-android-programmatically

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;
conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);

WifiManager wifiManager = (WifiManager)ba.applicationContext.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;
}
}

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

throw ex;
}
}
 

Attachments

  • USIWiFiLibrary.jar
    3.2 KB · Views: 300
  • USIWiFiLibrary.xml
    2.4 KB · Views: 337

DonManfred

Expert
Licensed User
Longtime User
Use code tags when posting code
 
Upvote 0
Top