Android

keep screen on

aucd29 2016. 2. 22. 14:24
private static PowerManager.WakeLock mWakeLock;

public static void setWakeLock(Context context) {
    if (context == null) {
        return ;
    }

    final PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);

    if (mWakeLock == null) {
        mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "WakeLock");
        mWakeLock.acquire();
    }
}

public static void releaseWakeLock() {
    if (mWakeLock != null) {
        mWakeLock.release();
        mWakeLock = null;
    }
}