Example: 關於Android framwork的Power management

開始之前:請閱讀


.
.

newWakeLockk的API

core/java/android/os/PowerManager.java 裡面的注解就大致說明了, 如何呼叫使用wake lock! 必須先newWakeLock(), 再acquire()使用, 最後要記得release()

/**
* Get a wake lock at the level of the flags parameter. Call
* {@link WakeLock#acquire() acquire()} on the object to acquire the
* wake lock, and {@link WakeLock#release release()} when you are done.
*
* {@samplecode
*PowerManager pm = (PowerManager)mContext.getSystemService(
* Context.POWER_SERVICE);
*PowerManager.WakeLock wl = pm.newWakeLock(
* PowerManager.SCREEN_DIM_WAKE_LOCK
* | PowerManager.ON_AFTER_RELEASE,
* TAG);

*wl.acquire();
* // …
*wl.release();
* }

*
* @param flags Combination of flag values defining the requested behavior of the WakeLock.
* @param tag Your class name (or other tag) for debugging purposes.
*
* @see WakeLock#acquire()
* @see WakeLock#release()
*/
public WakeLock newWakeLock(int flags, String tag)
{
if (tag == null) {
throw new NullPointerException(“tag is null in PowerManager.newWakeLock”);
}
return new WakeLock(flags, tag);
}

分類: 未分類

發表迴響