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

    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;
    }
    }
     

    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.
     
Loading...
  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