is Screen Off Or Locked - Android Phone

Android examples for Phone:Screen

Description

is Screen Off Or Locked

Demo Code


//package com.java2s;

import android.app.KeyguardManager;

import android.content.Context;

import android.os.PowerManager;

public class Main {
    private static boolean isScreenOffOrLocked(Context context) {
        KeyguardManager keyguardManager = (KeyguardManager) context
                .getSystemService(Context.KEYGUARD_SERVICE);
        PowerManager powerManager = (PowerManager) context
                .getSystemService(Context.POWER_SERVICE);
        boolean off = !powerManager.isScreenOn();
        off |= keyguardManager.inKeyguardRestrictedInputMode();
        return off;
    }/*from w w w.ja v a2s  . c  o m*/
}

Related Tutorials