各位大侠,
有谁知道android怎么连接未加密的无线指定无线网络啊?
例如我要连接的网络名称SSID为:TEST
目前,我在网络上搜索到的基本上是连接加密的无线网络。希望能得到高手的解答或思路。谢谢
有谁知道android怎么连接未加密的无线指定无线网络啊?
例如我要连接的网络名称SSID为:TEST
目前,我在网络上搜索到的基本上是连接加密的无线网络。希望能得到高手的解答或思路。谢谢
解决方案 »
- 如何监听短信会话(对话)的删除
- 真沮丧,硬是没看懂Android 4.0 WebView文本选择。
- ListView如何实现scroll到此view的底部后跳回顶部
- 高手请帮帮忙啊
- Android应用程序怎么通过socket跟守护进程通信?必须写一个framework层?怎么写?
- 问问Android多线程问题。
- 寻找Android系统级开发老师,(愿支付一定学费)
- 请教AndroidManifest.xml中的Service的name和Action的name可以不一样?
- Android中DES加密结果与java平台上不同如何解决
- 关于eclipse debug断点调试
- Android表格布局问题求解..
- 小菜一个简单的问题,莫鄙视,求回答,谢谢!
加上源码,我的链接不上指定的无线网络。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(); i++)
{
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"))
{
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");
}
}
}
}
}
});
}
}
if (networkId == -1) {
return;
} WifiConfiguration config = new WifiConfiguration();
config.networkId = networkId;
config.priority = ++mLastPriority;
mWifiManager.updateNetwork(config);
WifiConfiguration[] cfgs = mWifiManager.getConfiguredNetworks();
for (WifiConfiguration cfg : cfgs) {
if (cfg != null && cfg.status != Status.ENABLED) {
mWifiManager.enableNetwork(cfg.networkId, false);
}
}
mWifiManager.saveConfiguration(); // Connect to network by disabling others.
mWifiManager.enableNetwork(networkId, true);
mWifiManager.reconnect();
}