set Keep Screen On - Android android.app

Android examples for android.app:Screen

Description

set Keep Screen On

Demo Code

import android.app.Activity;
import android.view.WindowManager;

public class Main{

    public static void setKeepScreenOn(final Activity activity,
            final boolean keepScreenOn) {
        // WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
        if (keepScreenOn) {
            activity.getWindow().addFlags(
                    WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        } else {/*w  ww. j a v  a2 s .  c om*/
            activity.getWindow().clearFlags(
                    WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        }
    }

}

Related Tutorials