Java tutorial
//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; } }