public boolean waitForWifiState(int expectedState,long timeout){
  long startTime=System.currentTimeMillis();
  while (true) {
    if ((System.currentTimeMillis() - startTime) > timeout) {
      if (mWifiState != expectedState) {
        return false;
      }
 else {
        return true;
      }
    }
    Log.v(LOG_TAG,"Wait for wifi state to be: " + expectedState);
synchronized (mWifiMonitor) {
      try {
        mWifiMonitor.wait(SHORT_TIMEOUT);
      }
 catch (      InterruptedException e) {
        e.printStackTrace();
      }
      if (mWifiState != expectedState) {
        Log.v(LOG_TAG,"Wifi state is: " + mWifiState);
        continue;
      }
      return true;
    }
  }
}

public boolean waitForWifiState ( int expectedState , long timeout ) { long startTime = System . currentTimeMillis ( ) ; while ( true ) { if ( ( System . currentTimeMillis ( ) - startTime ) > timeout ) { if ( mWifiState != expectedState ) { return false ; } else { return true ; } } Log . v ( LOG_TAG , "Wait for wifi state to be: " + expectedState ) ; synchronized ( mWifiMonitor ) { try { mWifiMonitor . wait ( SHORT_TIMEOUT ) ; } catch ( InterruptedException e ) { e . printStackTrace ( ) ; } if ( mWifiState != expectedState ) { Log . v ( LOG_TAG , "Wifi state is: " + mWifiState ) ; continue ; } return true ; } } }
wait for a given wifi state to occur within a given timeout .
