我的应用不是 wifi状态更改(已连接或已断开连接)时接收广播。当app界面看不到
时,它正在工作我的清单:
我创建了BroadcastReceiver的子类并在manifest中声明,不需要注册BroadcastReceiver。
public class WifiReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) { WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE); NetworkInfo networkInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO); NetworkInfo.State detailedState = networkInfo.getState(); if (detailedState == NetworkInfo.State.CONNECTED && networkInfo.isConnected()) { ---do something---- } else if(detailedState == NetworkInfo.State.DISCONNECTED) { ---do something---- } } } }