My requirement is: after a GCM message arrives, the device should wake up to display a high-priority notification. The device should turn the screen on.
Currently I'm using WakeLock to achieve this. The newWakeLock()
method expects a lock level AND a flag to be passed (as the 1st param, bitwise or'd).
I'm using PowerManager.ACQUIRE_CAUSES_WAKEUP
flag since it does exactly what I need. However, I'm a bit frustrated about the lock level. So according to the docs, I got the following options:
PARTIAL_WAKE_LOCK
- not compatible withACQUIRE_CAUSES_WAKEUP
/ doesn't turn the screen onSCREEN_DIM_WAKE_LOCK
- deprecatedSCREEN_BRIGHT_WAKE_LOCK
- deprecatedFULL_WAKE_LOCK
- deprecated
The suggested FLAG_KEEP_SCREEN_ON
is completely useless in this scenario. I ended up just supressing the deprecation warning:
@SuppressWarnings("deprecation")
PowerManager.WakeLock screenOn = ((PowerManager) c.getSystemService(Context.POWER_SERVICE)).newWakeLock(
PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, TAG);
screenOn.acquire();
mNotifyMgr.notify(mNotificationId, mBuilder.build());
screenOn.release();
The question: is there a non-deprecated reliable way to wake up the device in the described case?
EDIT I'm not asking for workarounds to wake up the device. My question is whether this is possible to wake up the device from the background (without a running Activity
) using no deprecated APIs
Window
object while the app is in the background and noActivities
are running. So still looking for an answer – Marchland