private void registerNetWatcher() {
mConnReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if(mIsInited | mInitStart){
return;
};
ConnectivityManager connectMgr = (ConnectivityManager) mActivity
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = connectMgr.getActiveNetworkInfo();
NetworkInfo mobNetInfo = connectMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
NetworkInfo wifiNetInfo = connectMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (mobNetInfo != null && mobNetInfo.isAvailable()
&& mobNetInfo.isConnected()) {
if (!lList.equals("")
&& (updateDate
+ Constant.UPDATE_INTERVAL < currentDate)) {
initdata();
}
} else if (wifiNetInfo != null && wifiNetInfo.isAvailable()
&& wifiNetInfo.isConnected()) {
Log.i(TAG, "current net is WIFI");
initdata();
}
}
};
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
mActivity.registerReceiver(mConnReceiver, intentFilter);
}
转载于:https://www.cnblogs.com/yulincqupt/archive/2012/09/07/2674545.html