I am creating a timer using the Pomodoro Technique. The fist timer will be 20 minutes and in this time I expect the screen to turn off. I would like the screen to turn back on when the timer is finished.
In my manifest I have asked for the following permissions:
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
In my timer class I get the window in onCreat():
Window win;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_timer);
createTimer(time_work);
win = this.getWindow();
}
In my timer's onFinish() I call wakeUp():
public void onFinish() {
text_time.setText(R.string.done);
if (isWork) {
pomodoro_count++;
text_pomodoro_count.setText(String.valueOf(pomodoro_count));
}
isWork = !isWork;
onResume();
//I have more here but removed for brevity
wakeUp();
}
In wakeUp() I have tried every combination of this:
private void wakeUp() {
win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
win.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
}