我在致电 if( event->type() == QEvent::ShortcutOverride || event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease )
{
QKeyEvent *ev = static_cast<QKeyEvent *>(event);
if( ev->key()==Qt::Key_Return || ev->key()==Qt::Key_Enter )
{
QString receiver = obj->metaObject()->className();
foreach(QString acc, _classEatEnter)
if( receiver.contains(acc) )
{
event->accept(); // Prevent event propagation to parents
return false; // Allow obj to handle the "Enter" event
}
}
和WifiManager.setWifiEnabled(false)
后试图重新连接到以前的WiFi网络,但是我得到了“未知的SSID”。连接到网络后,我尝试使用WifiManager.setWifiEnabled(true)
,但一无所获。我也尝试获取配置列表,但重新启用后为空。我担心我做得太早了吗?以下代码不在广播接收器中,而是在checkedchangelistener中。
WifiManager.saveConfiguration()
如何自动重新连接到过去的WiFi网络?
更新
如果使用enableNetwork,它似乎会自动自动重新连接到最后一个,因此不需要mWifiManager.setWifiEnabled(true);
//the below comments don't work either. I tried.
//List<WifiConfiguration> configuredNetworks = mWifiManager.getConfiguredNetworks();
//if (configuredNetworks != null) {
//for (WifiConfiguration wifiConfiguration : configuredNetworks) {
// }
//}
//get connection info
WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
if (wifiInfo != null) {
RelativeLayout currentNetworkLayout =
generateCurrentNetworkLayout(mContext, wifiInfo.getSSID()
.replaceAll("^\"|\"$", ""));
mWifiListLayout.addView(currentNetworkLayout, 1);
}
。我认为我的代码以前是错误的。