实时获得机器network的状态

 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);
				}
			}
		};
registerReceiver(mNetworkStateIntentReceiver,
				mNetworkStateChangedFilter);

你可能感兴趣的:(java,UP)