可能重复:
How to connect to a specific wifi network in android programmatically?
我一直在尝试使用以下链接连接WEP无线网络的各种方法:
How do I connect to a specific Wi-Fi network in Android programmatically?
OR
How to programmatically create and read WEP/EAP WiFi configurations in Android?
我也尝试了引号,没有密码的引号。根本没有出现。也是上述两个链接的组合。
这是我试过的最后一次:
networkSSID = bundle.getString("networkName");
networkPass = bundle.getString("networkPassword");
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);
conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104);
Toast.makeText(getApplicationContext(), "pass is" + networkPass ,Toast.LENGTH_LONG).show();
Toast.makeText(getApplicationContext(), "id is" + networkSSID ,Toast.LENGTH_LONG).show();
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();
break;
}
}
我不确定问题出在哪里 - 当我通过我能够连接的设置手动连接到同一个WEP网络时。
如果有人可以就如何连接它给我一个正确的解决方案,那会很棒吗?
让我知道!!
谢谢!