gpt4 book ai didi

android - WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION 永远不会被解雇

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:05:28 26 4
gpt4 key购买 nike

我正在 onResume() 上注册接收器:

registerReceiver(wifiConnectivityReceiver, new
IntentFilter(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION));

这是接收器本身:

class WiFiConnectivityReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
if (intent.getBooleanExtra(WifiManager.EXTRA_SUPPLICANT_CONNECTED,false)){
Log.d(TAG,"Connected to network!");
} else {
Log.d(TAG,"Could not connect to network!");
}
}
}

在我的应用程序中,我能够连接到选定的 WiFi 网络,但是这个 SUPPLICANT_CONNECTION_CHANGE_ACTION 永远不会被触发。如果我​​将它更改为 SUPPLICANT_STATE_CHANGED_ACTION 例如它正在工作。

我正在研究 ICS。
有没有其他人遇到过这样的问题?

最佳答案

我认为以下代码可以帮助您:

public void installMyReceiver(){
if (I) Log.i(TAG, "installMyReceiver() - Online");
mFlag = true;


myReceiver = new BroadcastReceiver(){
public void onReceive (Context context, Intent intent){
String action = intent.getAction();

if (WifiManager.SUPPLICANT_STATE_CHANGED_ACTION.equals(action)){

SupplicantState supplicantState = (SupplicantState)intent.getParcelableExtra(WifiManager.EXTRA_NEW_STATE);
if (supplicantState == (SupplicantState.COMPLETED)){
if (I) Log.i(TAG, "SUPPLICANTSTATE ---> Connected");
//do something
}

if (supplicantState == (SupplicantState.DISCONNECTED)){
if (I) Log.i(TAG, "SUPPLICANTSTATE ---> Disconnected");
//do something
}

}
}
};

IntentFilter mFilter = new IntentFilter (WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);
this.registerReceiver (myReceiver, mFilter);
}

这是获取所需信息然后执行某些操作的简单方法。希望对您有所帮助!

关于android - WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION 永远不会被解雇,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14814742/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com