收到通知后如何使屏幕唤醒? [英] How to make a screen wake up when a notification is received?

查看:214
本文介绍了收到通知后如何使屏幕唤醒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的应用程序,我试图在通知唤醒屏幕并显示该应用程序视图的位置获取它.我不知道如何在锁定屏幕上唤醒应用程序.我已经尝试了一些方法,但似乎没有任何效果,或者它们使应用程序崩溃了.

For my app I'm trying to get it where the notification wakes up the screen and displays a view from the app. I can't figure how to get the app to wake up when its in a lock screen. I've tried a few things but none seem to work or they crash the app.

推荐答案

有我的解决方案:

createNotification(); //your implementation
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
boolean isScreenOn = Build.VERSION.SDK_INT >= 20 ? pm.isInteractive() : pm.isScreenOn(); // check if screen is on
if (!isScreenOn) {
    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "myApp:notificationLock");
    wl.acquire(3000); //set your time in milliseconds
}

更多信息,请访问 PowerManager

这篇关于收到通知后如何使屏幕唤醒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆