Using WifiManager to connect to a network

Showing 1-4 of 4 messages
Using WifiManager to connect to a network Daniel Rolph 2/1/10 5:21 AM
Hello everyone,

I am using a Nexus One with 2.1 SDK. I am having problems with a module in my application connecting programmatically to a network/AP. The code snippet that I am using is:

WifiConfiguration wifiConfig = new WifiConfiguration();
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
int netId = wifi.addNetwork(wifiConfig);
wifi.enableNetwork(netId, true);

Monitoring the network, I see probe requests transmitting from the device, but I do not see an Authentication/Association request to the access point that I specify in the BSSID. Ultimately, I will perform a scan to determine valid AP BSSIDs, but for testing, I simply want to connect to a test AP which is in close proximity to my Nexus One.

I have set the appropriate permissions in my manifest xml and am not seeing any negative log statements from adb.

Any pointers or suggestions with using WifiManager to perform this action would be very appreciated.

Thank you very much!


Daniel Rolph 2/2/10 12:30 PM <This message has been deleted.>
Re: Using WifiManager to connect to a network Neil 2/3/10 2:11 AM
I can't help with your protocol question, but the reason why
specifying the SSID isn't working is because it needs to be a quoted
value, e.g.

wifiConfig.SSID = "\"test\"";


On Feb 2, 8:30 pm, Daniel Rolph <> wrote:
> After digging around a little, I was able to put together the code to programmatically connect to an open network/AP.  For some reason, specifying the SSID causes the code not to connect.  

> WifiConfiguration wifiConfig = new WifiConfiguration();
> wifiConfig.BSSID = "00:0C:41:F5:B0:08";
> wifiConfig.priority = 1;
> wifiConfig.allowedKeyManagement.set(KeyMgmt.NONE);
> wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
> wifiConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
> wifiConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
> wifiConfig.status=WifiConfiguration.Status.ENABLED;

> WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
> int netId = wifi.addNetwork(wifiConfig);
> wifi.enableNetwork(netId, true);
> I am curious about the behavior of the network activity that I am seeing.  The N1 is constantly broadcasting Probe Requests.  The Access Point is sending out Probe Responses.   When I enable the network with the SDK, the N1 sends out a Probe Response with the SSID of the AccessPoint (probably determined from the Probe Response).   The N1 then sends out an Association Request to the AP and negotiates the connection.  Why can't I initiate an Association Request to the AP prior to receiving the AP Probe Response?  Basically, I would like to already have the AP defined in my WifiConfiguration and be sending Association Requests prior to being in range of the AP.  Is this possible or am I constrained by the protocol?

> Thank you very much!
> Dan
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to
> > To unsubscribe from this group, send email to
> >
> > For more options, visit this group at
> >

Re: [android-developers] Re: Using WifiManager to connect to a network Daniel Rolph 2/3/10 4:49 AM

Thanks for the catch on the SSID.  Actually, I find that I can only connect when I do not specify the SSID.  Documentation on wifi management is a little hard to come by.  I am learning the wifi packages and device/driver functionality through trial and error, logging,  and network monitoring.  I'll eventually get there.