void registerReceiver ( ) { if ( receiver == null ) { receiver = new NetworkReceiver ( new Listener ( ) { @ Override public void post ( NetworkChangeEvent event ) { if ( onNetworkChangedListener != null ) { onNetworkChangedListener . onChanged ( event ) ; } } } ) ; } final Context context = contextRef . get ( ) ; if ( context != null ) { IntentFilter filter = new IntentFilter ( ) ; filter . addAction ( ConnectivityManager . CONNECTIVITY_ACTION ) ; filter . addAction ( BluetoothAdapter . ACTION_STATE_CHANGED ) ; context . registerReceiver ( receiver , filter ) ; } }
Register network state broadcast receiver