I have a service that listens to push notifications and creates an activity. Everything works well except when the device's screen is off. The desired behavior is that a notification would wake the screen up to the locked state homescreen and display the notification.
I am only able to create this behavior with:
mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK |
PowerManager.ACQUIRE_CAUSES_WAKEUP |
PowerManager.ON_AFTER_RELEASE,
WAKELOCK_KEY);
However, I see that Android has deprecated FULL_WAKE_LOCK
in favor of FLAG_KEEP_SCREEN_ON. However, I have tried this in the activity that is called from the background service:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
And my logs show that this activity is being created but the screen still does not display this activity. If I press the power button, the display shows the activity immediately proving that it was created. Here is a summary of some of the things I have tried:
- FULL_WAKE_LOCK (works but is deprecated)
- WindowManager - FLAG_TURN_SCREEN_ON, FLAG_KEEP_SCREEN_ON (doesn't work)
- Google WakefulBroadCastReceiver (doesn't work)
Are there any alternatives to FULL_WAKE_LOCK
?