0
我有一個無線路由器,我試圖使連接這樣的:的Android,無線網絡重新連接不工作
WifiConfiguration wifiConfig = new WifiConfiguration();
wifiConfig.SSID = "\"" + wifiSSID + "\"";
wifiConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
wifiConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
wifiConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
wifiConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
wifiConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104);
wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
wifiConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
wifiConfig.preSharedKey = "\"" + wifiPassword + "\"";
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
int netId = wifiManager.addNetwork(wifiConfig);
Log.d("WIFI_RECONNECT", netId + "");
wifiManager.disconnect();
wifiManager.enableNetwork(netId, true);
boolean recon = wifiManager.reconnect();
Log.d("WIFI_RECONNECT", recon + "");
當我啓動這個代碼我在日誌中收到這樣的:
D/WIFI_RECONNECT: "My_WIFI_SSID" 1234567890
D/WIFI_RECONNECT: 67
D/WIFI_RECONNECT: true
然而,我的設備顯示我斷開了所有可以訪問的wifi路由器,我的路由器wifi網絡顯示在我的可用wifi列表中,但未處於連接模式。
爲什麼會發生這種情況?