How to connect to known WiFI using Intent in Android?

核能气质少年 提交于 2019-12-07 02:02:17

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/12747157/how-to-connect-to-known-wifi-using-intent-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!