acquire Lock from PowerManager - Android Android OS

Android examples for Android OS:Power

Description

acquire Lock from PowerManager

Demo Code

/**/*from   w  ww.j a v  a2  s . co  m*/
 * Project Name:TongCheng File Name:CommonUtil.java Package Name:com.taobao.tongcheng.util Date:2013-3-21 8:24:30
 * Copyright (c) 2013, weiping.yu@alibaba-inc.com All Rights Reserved.
 */
//package com.java2s;
import android.content.Context;
import android.os.PowerManager;

public class Main {
    private static PowerManager.WakeLock wakeLock;

    public static PowerManager.WakeLock acquireLock(Context context) {
        if (wakeLock == null || !wakeLock.isHeld()) {
            PowerManager powerManager = (PowerManager) context
                    .getSystemService(Context.POWER_SERVICE);
            wakeLock = powerManager.newWakeLock(
                    PowerManager.PARTIAL_WAKE_LOCK, "TT");
            wakeLock.setReferenceCounted(true);
            wakeLock.acquire();
        }
        return wakeLock;
    }
}

Related Tutorials