android学习 wifi连接的注意的问题

来源:互联网 发布:网络6524是什么意思啊 编辑:程序博客网 时间:2024/05/16 08:16

1。注意  xml String双引号“ ”的细节。

info.getSSID()

Open DeclarationString android.net.wifi.WifiInfo.getSSID()

Returns the service set identifier (SSID) of the current 802.11 network. If the SSID can be decoded as UTF-8,it will be returned surrounded by double quotation marks. Otherwise, it is returned as a string of hex digits. The SSID may benull if there is no network currently connected.

在用SharedPreferences存储相应 SSID时候, 对比匹配,要注意双引号的问题。。

 

2。public    List<WifiConfiguration>     getConfiguredNetworks()  

Upon failure to fetch or when when Wi-Fi is turned off, it can be null.

所以使用前要 先判断  wifiMangager.wifistate()== enabled时,才getConfiguredNetworks();否则空指针异常。 list返回NULL

 

 

 

总来说是 wifiMangager和SharedPreferences的运用。

 3.无认证的wifi总是连接不上

http://bbs.csdn.net/topics/390557674

config.wepKeys[0] = "\"" + "\"";这个原因;、

 

4.总是显示上一次连接

应该先 断开以前的wifi连接 wifiMangager.disconnect();再连接新的wifi。 以保障wifiMangager不会存储上次的信息

5.机顶盒重新开机后连不上  关机前保存的wifi.而不关机重新运行apk却可以

因为重启后硬件驱动启动需要时间, 所以重启的时候,先判断ConnectivityManager.getActiveNetworkInfo()是否为NULL, 直接延时30S。。。不过这样做是不是太慢了?

原创粉丝点击