欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Android Q 来通知后实现亮屏功能

程序员文章站 2022-03-23 22:09:24
最近实现来通知后亮屏修改代码:NotificationManagerService.java在函数enqueueNotificationInternal()最后添加 /*Begin: add for wake screen then new notification, 202009*/ PowerManager pm = (PowerManager) getContext().getSystemService(Context.POWER_SERVIC......

最近实现来通知后亮屏

修改代码:

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