如何从getScanResults()连接到网络

时间:2013-04-22 20:39:12

标签: android android-wifi

我想连接到WifiManager.getScanResults()结果中信号最强的wifi热点。但不知怎的,即使boolean b显示为真,我也无法启用我的设备访问网络。

  wc.SSID = "\".xxxxx\"";//result from the getScanResults()
            wc.preSharedKey  = "\"abcdefg111\"";
            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=false;
            b= wifi.enableNetwork(res, true);        
            Log.d("WifiPreference", "enableNetwork returned " + b );

0 个答案:

没有答案