PowerManager.WakeLock acquire - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for PowerManager.WakeLock acquire method.

This code example shows how to use the following methods:acquire, isHeld, release, setReferenceCounted
    if (cpuWakeLock == null) {
      PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
      if (pm != null) {
        cpuWakeLock =
            pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, TAG);
        cpuWakeLock.setReferenceCounted(true);
      } 
    } 
    if (cpuWakeLock != null) { //May be null if pm is null
      if (awake) {
        cpuWakeLock.acquire();
        L.d(TAG, "Adquired CPU lock");
      } else if (cpuWakeLock.isHeld()) {
        cpuWakeLock.release();
        L.d(TAG, "Released CPU lock");
      } 
    } 
  } 
 
  /** WiFi lock unique instance. */ 
9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:acquire
    } else if (connectivityListener == null) {
      IntentFilter filter  = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
      connectivityListener = new ConnectivityListener();
      context.registerReceiver(connectivityListener, filter);
 
      wakeLock.acquire();
    } 
  } 
 
  protected boolean isConnectivityPossible() { 
    NetworkInfo networkInfo = connectivityManager.getNetworkInfo(TYPE_MOBILE_MMS);
    Log.w("MmsService", "Got network info: " + networkInfo);
    return networkInfo != null  && networkInfo.isAvailable();
  } 
 
  protected void finishConnectivity() { 
    Log.w("MmsService", "Calling stop using network feature!");
    connectivityManager.stopUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE, FEATURE_ENABLE_MMS);
 
    if (connectivityListener != null) {
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:acquire
			wifiLock.release();
	} 
 
	public void onWakeLockSettingsChanged() { 
		if (SettingsManager.connectionWakeLock()) 
			wakeLock.acquire();
		else 
			wakeLock.release();
	} 
 
} 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:acquire
            PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
            Log.d(TAG, "PowerManager acquired");
            wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKE_LOCK_TAG);
            Log.d(TAG, "WakeLock set");
        } 
        wakeLock.acquire();
        Log.d(TAG, "WakeLock acquired");
    } 
 
    private void stopWakeLock() { 
        if (wakeLock != null) {
            wakeLock.release();
            Log.d(TAG, "WakeLock released");
        } 
    } 
 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:acquire, isHeld, release, setReferenceCounted
    if (cpuWakeLock == null) {
      PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
      if (pm != null) {
        cpuWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
            | PowerManager.ON_AFTER_RELEASE, TAG);
        cpuWakeLock.setReferenceCounted(true);
      } 
 
    } 
    if (cpuWakeLock != null) { //May be null if pm is null
      if (awake) {
        cpuWakeLock.acquire();
        L.d(TAG, "Adquired CPU lock");
      } else if (cpuWakeLock.isHeld()) {
        cpuWakeLock.release();
        L.d(TAG, "Released CPU lock");
      } 
    } 
  } 
 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:acquire, release
		if (!showNotification) {
			// only play sound and return 
			RingtoneManager.getRingtone(getApplicationContext(), mConfig.notifySound).play();
			return; 
		} 
		mWakeLock.acquire();
		setNotification(fromJid, fromUserName, message);
		setLEDNotification(); 
		mNotification.sound = mConfig.notifySound;
		 
		int notifyId = 0;
		if (notificationId.containsKey(fromJid)) {
			notifyId = notificationId.get(fromJid);
		} else { 
			lastNotificationId++;
			notifyId = lastNotificationId;
			notificationId.put(fromJid, Integer.valueOf(notifyId));
		} 
 
		// If vibration is set to "system default", add the vibration flag to the  

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:acquire
		} 
		 
		if (mWakeLock == null) {
    		PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
            mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "SyncMyPix WakeLock");
            mWakeLock.acquire();
    	} 
	} 
	 
	public static void releaseWakeLock() { 
    	if (mWakeLock != null) {
    		mWakeLock.release();
    		mWakeLock = null;
    	} 
	} 
} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:acquire
 
    public void acquireWakeLock() { 
        PowerManager manager = (PowerManager) mContext.getSystemService(
                Context.POWER_SERVICE);
        mWakeLock = manager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, mTag);
        mWakeLock.acquire();
        Log.d(mTag, "Wake lock acquired");
    } 
 
    public void releaseWakeLock() { 
        if(mWakeLock != null && mWakeLock.isHeld()) {
            mWakeLock.release();
            Log.d(mTag, "Wake lock released");
        } 
    } 
} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:acquire, setReferenceCounted
 
		// create the new wakelock and put it into the map 
		final WakeLock newWakeLock = mgr.newWakeLock(flags, id.toString());
 
		// if this wakelock doesn't already exist, continue 
		locks.put(id, newWakeLock);
		// only one at a time? TODO 
		newWakeLock.setReferenceCounted(false);
 
		if (releaseAfterMs == 0) {
			newWakeLock.acquire();
		} else { 
			newWakeLock.acquire(releaseAfterMs);
		} 
	} 
 
	public static void release(String id) {
		final WakeLock wakeLock = locks.get(id);
		// if there is was a wakelock, release it. (it has to be held) 
		try { 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:acquire
                // It can take hundreds of ms flush the audio pipeline after 
                // apps pause audio playback, but audio route changes are 
                // immediate, so delay the route change by 1000ms. 
                // This could be improved once the audio sub-system provides an 
                // interface to clear the audio pipeline. 
                mWakeLock.acquire();
                mHandler.sendEmptyMessageDelayed(0, 1000);
            } else { 
                updateAudioRoute(); 
            } 
        } 
    } 
 
    private synchronized final void sendIntent(boolean isUnplug) {
        //  Pack up the values and broadcast them to everyone 
        Intent intent = new Intent(Intent.ACTION_HEADSET_PLUG);
        intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
 
        intent.putExtra("state", mHeadsetState);
        intent.putExtra("name", mHeadsetName);
7
CodeRank
Experience pair programming with AI  Get Codota for Java

Related PowerManager.WakeLock acquire Questions & Answers:

Other PowerManager.WakeLock acquire Examples

13:	                PowerManager.ACQUIRE_CAUSES_WAKEUP |
14:	                PowerManager.ON_AFTER_RELEASE, "WakeLock");
15:	        wakeLock.acquire();
16:	    }
17:

Read More

acquire Method Overview
Acquires the wake lock.
See Code Examples for other Android PowerManager.WakeLock Methods: