I managed to solve the problem. When starting my activity I use WakeLock
:
PowerManager pm = ((PowerManager) getSystemService(POWER_SERVICE));
screenLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG");
screenLock.acquire();
This code will prevent the screen to turn off. But after that I start a timer with delay of few seconds and it disables the WakeLock
:
if(screenLock.isHeld()) {
screenLock.release();
}