Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect to known WiFI using Intent in Android?

I've got something like this:

wifiNetworks = (ArrayList<ScanResult>) mWifiManager.getScanResults();

Now I can simply get wifi SSID:

wifiNetworks.get(0).SSID

I don't know if network is WEP, WPA, does it have password or not, so I just want to create an Intent, put there SSID or ScanResult and send it to Settings or wherever in order to let user to enter the password and connect to that network. Is it possible? And if not, what is the easiest way to get information about network type and connect programatically to it?

like image 580
user1723095 Avatar asked Oct 05 '12 13:10

user1723095


1 Answers

Check out this link: How do I connect to a specific Wi-Fi network in Android programmatically?.

ScanResult has everything you need to know about the network.

wifiNetworks.get(0).capabilities

gives a string.

capabilities format = [security-key-group cipher]<[security]>

Just separate these 3 values using "-" as separator and get the security.

security can have the following values:

OPEN
WEP
WPA
WPA2    

If security = "WEP" then key and group cipher are null.

like image 105
Vikram Gupta Avatar answered Oct 27 '22 09:10

Vikram Gupta