Wake ups and release the screen lock. - Android User Interface

Android examples for User Interface:Screen Lock

Description

Wake ups and release the screen lock.

Demo Code


//package com.java2s;
import android.app.KeyguardManager;
import android.content.Context;

import android.os.PowerManager;

public class Main {
    /**/*ww  w  .ja va 2s.  com*/
     * Wake ups and release the screen lock.
     * @param context
     */
    public static void wakeLockWithScreenUnLock(Context context) {
        partialWakeUpLock(context);
        releaseScreenLock(context);
    }

    /**
     * Wake ups the phone.
     * @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();
    }

    /**
     * Release the devices screen lock.
     * @param context
     */
    public static void releaseScreenLock(Context context) {
        KeyguardManager keyguardManager = (KeyguardManager) context
                .getApplicationContext().getSystemService(
                        Context.KEYGUARD_SERVICE);
        KeyguardManager.KeyguardLock keyguardLock = keyguardManager
                .newKeyguardLock("TAG");
        keyguardLock.disableKeyguard();
    }
}

Related Tutorials