Android Question Error while connecting to WiFi network

Discussion in 'Android Questions' started by Harish Kumar Arya, Mar 16, 2015.

  1. Harish Kumar Arya

    Harish Kumar Arya Member 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;

    Attached Files:

  2. DonManfred

    DonManfred Expert Licensed User

    Use code tags when posting code
  3. Erel

    Erel Administrator Staff Member Licensed User

    luke2012 likes this.
  4. Harish Kumar Arya

    Harish Kumar Arya Member Licensed User

    Thanks Erel,

    I will look through them.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice