我想让用户通过我的应用程序连接到WiFi网络,当用户设法输入正确的WiFi密码时连接正常,但当他输入错误的WiFi密码时,两个出现了不受欢迎的问题:
我正在使用带有以下BroadcastReceiver
说明的manifest
检测到WiFi连接发生变化:
<receiver android:name="com.automation.standards.WifiReceiver">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
</intent-filter>
</receiver>
以下列方式处理变更:
WifiManager wifiMgr = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
if(wifiMgr.isWifiEnabled()){
Toast.makeText(mContext, "wifi is enabled", Toast.LENGTH_LONG).show();
}
WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
String connected_net = (wifiInfo.getSSID()).toString(); // Here I'm getting the failed-in-connection WiFi Net
以及当用户按下连接并输入密码时如何连接到WiFi网络:
final WifiManager wifiManager = (WifiManager)(mContext).getSystemService(Context.WIFI_SERVICE);
wifiManager.addNetwork(conf); // Adding the Network Configuration to the WifiManager
wifiManager.disconnect();
wifiManager.enableNetwork(conf.networkId, true);
wifiManager.reconnect();
wifiManager.saveConfiguration();