public static void turnScreenOn ( Activity context ) { try { Window window = context . getWindow ( ) ; window . addFlags ( WindowManager . LayoutParams . FLAG_DISMISS_KEYGUARD ) ; window . addFlags ( WindowManager . LayoutParams . FLAG_SHOW_WHEN_LOCKED ) ; window . addFlags ( WindowManager . LayoutParams . FLAG_TURN_SCREEN_ON ) ; } catch ( Exception ex ) { Log . e ( "Caffeine" , "Unable to turn on screen for activity " + context ) ; } }
Force screen to turn on if the phone is asleep .