当前位置: 代码迷 >> Android >> 设立 Android wifi连接 samples【转】
  详细解决方案

设立 Android wifi连接 samples【转】

热度:568   发布时间:2016-05-01 16:24:51.0
设置 Android wifi连接 samples【转】

原文地址:http://stackoverflow.com/questions/2140133/how-and-what-to-set-to-android-wificonfiguration-presharedkey-to-connect-to-the-w
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);WifiConfiguration wc = new WifiConfiguration();// This is must be quoted according to the documentation // http://developer.android.com/reference/android/net/wifi/WifiConfiguration.html#SSIDwc.SSID = "\"SSIDName\"";wc.preSharedKey ?= "password";wc.hiddenSSID = true;wc.status = WifiConfiguration.Status.ENABLED; ? ? ? ?wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN);int res = wifi.addNetwork(wc);Log.d("WifiPreference", "add Network returned " + res );boolean b = wifi.enableNetwork(res, true); ? ? ? ?Log.d("WifiPreference", "enableNetwork returned " + b );

1 楼 wangtuwen 2011-11-28  
请问一下,我使用了你这个方法去连接,怎么都连不上呢!
每次wifi.addNetwork(wc);
之后,返回的都是-1

2 楼 04023129 2011-12-02  
试下 把wc.preSharedKey  = "password";
改成wc.preSharedKey  = "\"password\"";
  相关解决方案