Java tutorial
//package com.java2s; //License from project: Apache License import android.app.Activity; import android.view.WindowManager; public class Main { public static void setKeepScreenOn(Activity activity, boolean setkeepScreenOn) { if (null == activity) return; // activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, // WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } }