public static void keepWiFiOn ( Context context , boolean on ) { if ( wifiLock == null ) { WifiManager wm = ( WifiManager ) context . getSystemService ( Context . WIFI_SERVICE ) ; if ( wm != null ) { wifiLock = wm . createWifiLock ( WifiManager . WIFI_MODE_FULL , TAG ) ; wifiLock . setReferenceCounted ( true ) ; } } if ( wifiLock != null ) { // May be null if wm is null if ( on ) { wifiLock . acquire ( ) ; L . d ( TAG , "Adquired WiFi lock" ) ; } else if ( wifiLock . isHeld ( ) ) { wifiLock . release ( ) ; L . d ( TAG , "Released WiFi lock" ) ; } } }
Register a WiFi lock to WiFi management in the device .