Android Screen On turnScreenOn(Activity context)

Here you can find the source of turnScreenOn(Activity context)

Description

Purpose - Force screen to turn on if the phone is asleep.

Parameter

Parameter Description
context The current Activity Context from which this method is called

Declaration

public static void turnScreenOn(Activity context) 

Method Source Code

//package com.java2s;

import android.app.Activity;

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

public class Main {
    /**/*from  w  ww. j a v a  2  s  .co  m*/
     * Purpose - Force screen to turn on if the phone is asleep.
     *
     * @param context The current Activity Context from which this method is called
     */
    public static void turnScreenOn(Activity context) {
        if (context == null)
            return;
        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("Adroit", "Unable to turn on screen for activity "
                    + context);
        }
    }
}

Related

  1. keepScreenOn(final Activity pActivity)
  2. keepScreenOn(final Activity pActivity)