本文介绍了如何连接到不安全的无线网络?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的所有人,
我需要你的帮助.我使用Android以指定的名称(例如"TEST")连接到不安全的无线网络;
我使用打击代码进行测试,但失败了.有人可以帮我吗?
Dear All,
I need your help. I use Android to connect to an unsecure wireless network with the name specified, such as "TEST";
I use blow code for test, but it fails. So could any one help me?
public class WifiConnActivity extends Activity {
/** Called when the activity is first created. */
final String tag = "WifiConn:...";
EditText txt;
WifiManager mWifi;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mWifi = (WifiManager)getSystemService(Context.WIFI_SERVICE);
txt = (EditText)findViewById(R.id.editText1);
Button b1 = (Button)findViewById(R.id.B1);
b1.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v)
{
if (mWifi.startScan())
{
Log.d(tag, "startScan()");
List<scanresult> sRet = mWifi.getScanResults();
for (int i=0; i<sret.size();> {
ScanResult retS = sRet.get(i);
txt.append("resT: " + retS.SSID +" " + retS.BSSID + "\n");
Log.d(tag, "resT: " + retS.SSID +" " + retS.BSSID);
if (retS.SSID.equalsIgnoreCase("TEST")) // TEST is wireless SSID
{
txt.append("Found: " + retS.SSID +" " + retS.BSSID + "\n");
WifiConfiguration wc = new WifiConfiguration();
wc.SSID = "\""+retS.SSID+"\"";
wc.BSSID = retS.BSSID;
wc.status = WifiConfiguration.Status.ENABLED;
wc.hiddenSSID = true;
int netID = mWifi.addNetwork(wc); // add network
txt.append("addNetwork: "+ Integer.toString(netID) +"\n");
if(mWifi.enableNetwork(netID, true)) // enable network
{
txt.append("enableNetwork: true\n");
}
}
}
}
}
});
}
}
推荐答案
wc.wepKeys[0] = "";
wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
wc.wepTxKeyIndex = 0;
这篇关于如何连接到不安全的无线网络?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!