Code example for PowerManager

Methods: isScreenOn

     * @return true if the screen is on and not locked; false otherwise, in which case tests that 
     * send key events will fail. 
    public static boolean isScreenOnAndNotLocked(Context context) {
        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        if (!pm.isScreenOn()) {
            return false; 
        KeyguardManager km = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
        if (km.inKeyguardRestrictedInputMode()) {
            return false; 
        return true; 
    public static void assertViewVisible(View v) {
        if (v == null) {
            throw new NullPointerException();
        for (;;) { 
Connect your IDE to all the code out there  Get Codota for Java