Code example for NetworkInfo

Methods: getDetailedState, isConnected

0
                if (!mConnected.get()) { 
                    handleStateChanged(WifiInfo.getDetailedStateOf((SupplicantState) 
                            intent.getParcelableExtra(WifiManager.EXTRA_NEW_STATE))); 
                } 
            } else if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) { 
                NetworkInfo info = (NetworkInfo) intent.getParcelableExtra( 
                        WifiManager.EXTRA_NETWORK_INFO); 
                mConnected.set(info.isConnected()); 
                handleStateChanged(info.getDetailedState()); 
            } 
        } 
    }; 
 
    public WifiEnabler(Context context, Switch switch_) {
        mContext = context;
        mSwitch = switch_;
 
        mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        mIntentFilter = new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION);
        // The order matters! We really should not depend on this. :( 
        mIntentFilter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);