turn Screen On - Android android.app

Android examples for android.app:Screen

Description

turn Screen On

Demo Code

import android.app.Activity;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;

public class Main {

  /**//from   www  .  j ava 2  s .c o m
   * Force screen to turn on if the phone is asleep.
   *
   * @param context
   *          The current Context or Activity that this method is called from
   */
  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("PercolateAndroidUtils", "Unable to turn on screen for activity " + context);
    }
  }

}

Related Tutorials