判断不同网络,作不同操作

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);
    }

posted @ 2012-09-07 09:28  yulincqupt  阅读(179)  评论(0编辑  收藏  举报