如何使用 SSID 连接到特定的 Wifi 网络?我试过使用下面的代码。
wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiConfiguration config = new WifiConfiguration();
if(wifi.startScan()){
List<ScanResult> results = wifi.getScanResults();
for(int i=0;i<results.size();i++)
{ Log.e("VALUE"," "+results.get(i).toString());
Log.e("",""+results.get(i).SSID);
if(results.get(i).SSID.equalsIgnoreCase("\"MAC\""))
{
Log.e("","mac.....");
try{
String ssid="\""+results.get(i).SSID+"\mac"";
Log.e("SSId"," "+ssid);
config.SSID=ssid;
}catch(Exception e){Log.e("","Error : "+e.toString());}
config.preSharedKey="0a0b0f62170ecc5bcf721b6ff170b8b560101b5d56b00a26abec217e0bb4aa1f";
config.status=WifiConfiguration.Status.ENABLED;
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
config.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
int res=wifi.addNetwork(config);
Log.e("ENABLE ",""+wifi.enableNetwork(res, false));
break;
}
}
}
我在任何地方都没有找到有关如何执行此操作的任何信息?我哪里错了?