0
我無法連接Android上建立的SSID,我嘗試WifiConfiguration但未完成,我的ssid已打開(無密碼)。如何將Android連接至無SSID public並且無密碼要求
在Android UI中,我可以連接,但在代碼上我不能。
有人幫我嗎?
Tankyou。
編輯:
我的代碼:
String networkSSID = "DL63.0.0.0.1";
String networkPass = "";
WifiConfiguration conf = new WifiConfiguration();
conf.SSID = "\"" + networkSSID + "\"";
// conf.wepKeys[0] = "\"" + networkPass + "\"";
// conf.wepTxKeyIndex = 0;
conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
// conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
WifiManager wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
wifiManager.addNetwork(conf);
List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
for (WifiConfiguration i : list) {
if (i.SSID != null && i.SSID.equals("\"" + networkSSID + "\"")) {
wifiManager.disconnect();
wifiManager.enableNetwork(i.networkId, true);
wifiManager.reconnect();
Toast.makeText(this, "SSID: "+wifiManager.getConnectionInfo().getSSID(), Toast.LENGTH_SHORT).show();
break;
}
}
status.setText("SSID: "+wifiManager.getConnectionInfo().getSSID());
請顯示您的代碼...你究竟試過了什麼? – Yahia 2012-01-30 19:30:17
我嘗試這兩個代碼(答案2和3):http://stackoverflow.com/questions/8818290/how-to-connect-to-a-specific-wifi-network-in-android-programmatically – 2012-01-30 19:41:55
究竟發生了什麼?任何異常/錯誤消息? – Yahia 2012-01-30 19:43:45