Android Q 来通知后实现亮屏功能
最近实现来通知后亮屏
修改代码:
NotificationManagerService.java
在函数enqueueNotificationInternal()最后添加
/*Begin: add for wake screen then new notification, 202009*/
PowerManager pm = (PowerManager) getContext().getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock((PowerManager.ACQUIRE_CAUSES_WAKEUP
| PowerManager.SCREEN_BRIGHT_WAKE_LOCK), "Notification");
final StatusBarNotification sn = r.sbn;
NotificationRecord old = mNotificationsByKey.get(sn.getKey());
if (old != null) {//此处判断的作用是防止下载的通知一直不停的亮屏
//status update //进度条的通知不亮屏
} else {
//status new //新通知时亮屏
wl.acquire();
}
/*End: add for wake screen then new notification, 202009*/
mHandler.post(new EnqueueNotificationRunnable(userId, r));
测试OK
本文地址:https://blog.csdn.net/hmily0917/article/details/108583635