IntentFilter mNetworkStateChangedFilter = new IntentFilter();
mNetworkStateChangedFilter .addAction(ConnectivityManager.CONNECTIVITY_ACTION); mNetworkStateIntentReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals( ConnectivityManager.CONNECTIVITY_ACTION)) { boolean down = intent.getBooleanExtra( ConnectivityManager.EXTRA_NO_CONNECTIVITY, false); //对network的up or down 进行处理 onNetworkToggle(!down); } } }; egisterReceiver(mNetworkStateIntentReceiver, mNetworkStateChangedFilter); |
转载于:https://blog.51cto.com/broxigar/712640