我可以使用以下code
添加网络,但如果在authentication
Enable
和Network
之后添加或reconnect
失败,则无法获取状态。请帮忙!!!
mWifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
removeNetwork();
Boolean isWifiConnected = false;
WifiConfiguration mWifiConf = new WifiConfiguration();
mWifiConf.SSID = "\"" + networkList.get(item_pos).SSID + "\"";
mWifiConf.hiddenSSID = true;
mWifiConf.status = WifiConfiguration.Status.ENABLED;
mWifiConf.priority = 1;
if(addWPA2Network(mWifiConf, etPassword.getText().toString())<0)
{
}
else
{
List<WifiConfiguration> list = mWifiManager.getConfiguredNetworks();
for (WifiConfiguration i : list)
{
if (i.SSID != null && i.SSID.equals("\"" + networkList.get(item_pos).SSID + "\""))
{
mWifiManager.disconnect();
isWifiConnected = mWifiManager.enableNetwork(i.networkId, true);
isWifiConnected = mWifiManager.reconnect();
break;
}
}
}
答案 0 :(得分:0)
将网络的android权限添加到清单文件中。
答案 1 :(得分:0)
if (intent.getAction().equals(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION)) {
handleSupplicantStateChanged(
(SupplicantState) intent.getParcelableExtra(WifiManager.EXTRA_NEW_STATE),
intent.hasExtra(WifiManager.EXTRA_SUPPLICANT_ERROR),
intent.getIntExtra(WifiManager.EXTRA_SUPPLICANT_ERROR, 0));
}
使用此处理程序检查其连接是否成功。