Example usage for android.os PowerManager newWakeLock

List of usage examples for android.os PowerManager newWakeLock

Introduction

In this page you can find the example usage for android.os PowerManager newWakeLock.

Prototype

public WakeLock newWakeLock(int levelAndFlags, String tag) 

Source Link

Document

Creates a new wake lock with the specified level and flags.

Usage

From source file:Main.java

public static void acquire(Context context) {
    if (wakeLock != null)
        wakeLock.release();/*from  w w  w.j  ava  2 s.  c o  m*/

    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    wakeLock = pm.newWakeLock(
            PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE,
            "WakeLock");
    wakeLock.acquire();
}

From source file:Main.java

public static void setWakeLock(Context context) {

    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, TAG);
    wl.acquire();/* www  .jav  a  2s  .c  om*/
}

From source file:Main.java

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();//from   www .j a v  a  2  s  .  c  o m
    }
    return wakeLock;
}

From source file:Main.java

public static void acquireWakeLock(Context context) {
    if (wakeLock == null) {
        PowerManager powerManager = (PowerManager) (context.getSystemService(Context.POWER_SERVICE));
        wakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag");
        wakeLock.acquire();/*from w ww .  j a  va2 s  .co m*/
    }
}

From source file:Main.java

/**
 * Hold wake lock./*from   w ww  .j a  v  a2s  .  c  o m*/
 *
 * @param context
 *     the context
 */
public static void holdWakeLock(Context context) {
    PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakeLock");
    wakeLock.acquire();
}

From source file:Main.java

public static void wakeLockOn(Context context) {
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    if (wl == null)
        wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "CLOCK_ALARM");
    wl.acquire();//ww w.  ja  v  a 2s  .c  o  m
}

From source file:Main.java

/**
 * Show the activity over the lockscreen and wake up the device. If you
 * launched the app manually both of these conditions are already true. If
 * you deployed from the IDE, however, this will save you from hundreds of
 * power button presses and pattern swiping per day!
 */// www  .j av  a2s .c o  m
public static void riseAndShine(Activity activity) {
    activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);

    PowerManager power = (PowerManager) activity.getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock lock = power.newWakeLock(
            PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE,
            "wakeup!");

    lock.acquire();
    lock.release();
}

From source file:Main.java

public static void acquireTemporaryWakelocks(Context context, long timeout) {
    if (wakeLock == null) {
        PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP
                | PowerManager.ON_AFTER_RELEASE, "PushSMS");
    }//from   w ww . ja v a 2  s. c om
    wakeLock.acquire(timeout);

    if (wifiLock == null) {
        WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        wifiLock = wifiManager.createWifiLock("PushSMS");
    }

    wifiLock.acquire();
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            wifiLock.release();
        }
    }, timeout);
}

From source file:Main.java

/**
 * Wake ups the phone.//from  w  w w  .j  a v  a2 s .co m
 * @param context
 */
public static void partialWakeUpLock(Context context) {
    PowerManager pm = (PowerManager) context.getApplicationContext().getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK
            | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG");
    wakeLock.acquire();
}

From source file:Main.java

public static void toggleWalkLook(Context context, boolean tag) {

    PowerManager powerManager = (PowerManager) context.getSystemService(Service.POWER_SERVICE);
    PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Lock");
    wakeLock.setReferenceCounted(false);
    if (tag)//from w w w  .ja  v a  2  s .c o  m
        wakeLock.acquire();
    else
        wakeLock.release();

}