Bring app to front, turn on display and unlock from AlarmManager?

不羁岁月 提交于 2019-11-28 20:55:13

You should acquire wake lock with PowerManager.ACQUIRE_CAUSES_WAKEUP and PowerManager.FULL_WAKE_LOCK.

WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TRAININGCOUNTDOWN"); 

Bear also in mind that if you release wake lock right after startActivity() is called, the activity might not start because it is asynchronous call. I suggest to use WakefulServiceIntent or PowerManager.WakeLock.acquire(long timeout)

In the DescClock it is done in the following way:

    final Window win = getWindow();
    win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
            | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
    // Turn on the screen unless we are being launched from the AlarmAlert
    // subclass.
    if (!getIntent().getBooleanExtra(SCREEN_OFF, false)) {
        win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
                | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);
    }

Go to the Activity which you want to start in onReceive(). Paste this in onCreate() of that Activity

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

As I can see onReceive is called with pendingIntent interval. On my device only the first call of onReceive was acquire the WakeLock. If I press the suspend button in the meantime the second call of wl.acquire() was not able to bring the system up. I need a release() first followed by a acquire()

wl.release();
wl.acquire();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!