Android WifiManager.WifiLock - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android WifiManager.WifiLock class.

This code example shows how to use the following methods:acquire, isHeld, release, setReferenceCounted
  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");
      } 
    } 
  } 
} 
9
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:isHeld, release
 
	/** 
	 * 
	 */ 
	public void cleanup() { 
		if (mWifiLock.isHeld())
			mWifiLock.release();
 
		mTerminalManager.unregisterReceiver(this);
	} 
 
	/** 
	 * Increase the number of things using the network. Acquire a Wi-Fi lock 
	 * if necessary. 
	 */ 
	public void incRef() { 
		synchronized (mLock) {
			mNetworkRef  += 1;
 
			acquireWifiLockIfNecessaryLocked(); 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:isHeld, release
 
	/** 
	 * 
	 */ 
	public void cleanup() { 
		if (mWifiLock.isHeld())
			mWifiLock.release();
 
		mTerminalManager.unregisterReceiver(this);
	} 
 
	/** 
	 * Increase the number of things using the network. Acquire a Wi-Fi lock 
	 * if necessary. 
	 */ 
	public void incRef() { 
		synchronized (mLock) {
			mNetworkRef  += 1;
 
			acquireWifiLockIfNecessaryLocked(); 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:acquire
		ConnectionManager.getInstance().updateConnections(false); 
	} 
 
	public void onWifiLockSettingsChanged() { 
		if (SettingsManager.connectionWifiLock()) 
			wifiLock.acquire();
		else 
			wifiLock.release();
	} 
 
	public void onWakeLockSettingsChanged() { 
		if (SettingsManager.connectionWakeLock()) 
			wakeLock.acquire();
		else 
			wakeLock.release();
	} 
 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:isHeld, release
            mPlayer.release();
            mPlayer = null;
        } 
 
        // release the Wifi lock, if holding it 
        if (mWifiLock.isHeld()) {
            mWifiLock.release();
        } 
    } 
 
     
    /** 
     * Fully releases the audio focus. 
     */ 
    private void giveUpAudioFocus() { 
        if (mAudioFocus == AudioFocus.FOCUS 
                && mAudioManager != null  
                && AudioManager.AUDIOFOCUS_REQUEST_GRANTED == mAudioManager.abandonAudioFocus(this))  {
             
            mAudioFocus = AudioFocus.NO_FOCUS;
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:acquire, isHeld, release, setReferenceCounted
  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");
      } 
    } 
  } 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:isHeld, release
            mPlayer.release();
            mPlayer = null;
        } 
 
        // we can also release the Wifi lock, if we're holding it 
        if (mWifiLock.isHeld()) mWifiLock.release();
    } 
 
    void giveUpAudioFocus() { 
        if (mAudioFocus == AudioFocus.Focused && mAudioFocusHelper != null
                                && mAudioFocusHelper.abandonFocus())
            mAudioFocus = AudioFocus.NoFocusNoDuck;
    } 
 
    /** 
     * Reconfigures MediaPlayer according to audio focus settings and starts/restarts it. This 
     * method starts/restarts the MediaPlayer respecting the current audio focus state. So if 
     * we have focus, it will play normally; if we don't have focus, it will either leave the 
     * MediaPlayer paused or set it to a low volume, depending on what is allowed by the 
     * current focus settings. This method assumes mPlayer != null, so if you are calling it, 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setReferenceCounted
	 */ 
	synchronized private static WifiLock getWifiLock(Context context) {
		if (mWifiLock == null) {
			WifiManager mgr = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
			mWifiLock = mgr.createWifiLock(TAG);
			mWifiLock.setReferenceCounted(true);
		} 
		return mWifiLock;
	} 
} 
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:isHeld, release
  public void onPause() { 
    super.onPause(); 
 
    videoView.pause();
 
    if (wifiLock != null && wifiLock.isHeld()) {
      wifiLock.release();
    } 
  } 
 
  @Override 
  public boolean onError(final MediaPlayer mp, final int what, final int extra) {
    Log.e(TAG, "Media player error " + what + "/" + extra);
    switch (what) {
    case MediaPlayer.MEDIA_ERROR_SERVER_DIED:
      openVideo(); 
      return true; 
    default: 
      new ErrorDialogFragment().show(getFragmentManager(), "error"); 
      return true; 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:isHeld, release
  public void onPause() { 
    super.onPause(); 
 
    videoView.pause();
 
    if (wifiLock != null && wifiLock.isHeld()) {
      wifiLock.release();
    } 
  } 
 
  @Override 
  public boolean onError(final MediaPlayer mp, final int what, final int extra) {
    Log.e(TAG, "Media player error " + what + "/" + extra);
    switch (what) {
    case MediaPlayer.MEDIA_ERROR_SERVER_DIED:
      openVideo(); 
      return true; 
    default: 
      new ErrorDialogFragment().show(getFragmentManager(), "error"); 
      return true; 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Android WifiManager.WifiLock Questions & Answers:

See Code Examples for Android WifiManager.WifiLock Methods: