FLAG_TURN_SCREEN_ON not working

I have a service with a registered accelerometer inside. When a specific shake pattern is recognized, the service starts one action using this code.

Intent launchIntent = new Intent("my.package.MAIN_ACTIVITY");
LaunchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(LaunchIntent);

Q onCreateI use this code snippet to unlock the phone and turn on the screen:

Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
                WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON|
                WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

If the user does not interact with the activity for a while, I use this code to turn off the display:

Window window = getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

If the display turns off and the phone locks while the action is displayed, and I repeat the jitter pattern, the called method onStart. I tried to include the same code to enable and unlock as above, but it does not work (the display does not turn on).

What could be the problem?

+4
1

. , WakeLock:

PowerManager pm = ((PowerManager) getSystemService(POWER_SERVICE));
screenLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG");
screenLock.acquire();

. ​​ WakeLock:

if(screenLock.isHeld()) {
    screenLock.release();
}
+4

All Articles