android wifi代理 网络连接不上,android-无法连接到WiFi网络
我是Android开发的新手,正在尝试使用Android SDK连接到WiFi网络.断开连接的代码工作正常,但重新连接失败.这是我的代码try {WifiConfiguration conf = new WifiConfiguration();conf.SSID = "\"" + networkSSID + "\"";// Please note the quotes. String sho...
我是Android开发的新手,正在尝试使用Android SDK连接到WiFi网络.断开连接的代码工作正常,但重新连接失败.这是我的代码
try {
WifiConfiguration conf = new WifiConfiguration();
conf.SSID = "\"" + networkSSID + "\""; // Please note the quotes. String should contain SSID in quotes
conf.wepKeys[0] = password; //WEP password is in hex, we do not need to surround it with quotes.
conf.wepTxKeyIndex = 0;
conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
WifiManager wifiManager = (WifiManager)ba.applicationContext.getSystemService(Context.WIFI_SERVICE);
wifiManager.addNetwork(conf);
List 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;
}
}
//WiFi Connection success, return true
return true;
} catch (Exception ex) {
throw ex;
}
我将此代码包装在一个用在其他应用程序中的jar文件中.当我调用此方法并尝试使用SSID和密码连接到WEP网络时,我不断收到以下错误消息:
android.system.ErrNoException: recvfrom failed: ETIMEDOUT (Connection timed out).
该错误确实表明某处存在连接超时,但是我无法弄清楚该错误来修复我的代码.我可以在代码中引入任何指针和更改以使其工作?
Paritosh
更多推荐
所有评论(0)