For waking a device and turning screen on, you've the following options:
Use PowerManager Wakelock technique.
Or
Use WindowManager LayoutParams Flags.
For going with first option,
problem is the wakelock constructor takes two flags with a OR operator. One level, another Flag.
PowerManager pm = (PowerManager)
getSystemService
(Context.POWER_SERVICE);
wl = pm.newWakeLock
(PowerManager.SCREEN_BRIGHT_
WAKE_LOCK|
PowerManager.ACQUIRE_CAUSES_
WAKEUP, "bbbb");
wl.acquire();
Here, nothing's wrong but , SCREEN_BRIGHT_
WAKE_LOCK and other flags have been deprecated and there's no Level flag that could work with ACQUIRE_CAUSES_
WAKEUP.
It's a good thing since wakelock usage is discouraged.
Second option
FLAG_TURN_SCREEN_ON
LayoutParams Flags are the recommended way, but there's a catch that those flags, once set, work only during a window is created.
That means, you've to set them in your onCreate method before anything else., otherwise they won't work reliably.
So, that invalidates the scope of any condition checking before setting the flags, which could be handled by an extra Activity in control flow. ;) I'll leave it up to here.
No comments:
Post a Comment