内推
【长期有效】欢迎加入字节跳动我的团队:内推链接
从一个bug说起,前阵子拿Nexus 6P(Android 8.0)进行通知推送的测试,发现无法弹出通知栏。
项目跑在Android 8.0模拟器上弹出了Toast:
Developer warning for package “xxx.xxx.xxx”
Failed to post notification on channel “12345”
See log for more details
然后查看log,system_process显示一条error log:
NotificationService: No Channel found for pkg=xxx.xxx.xxx, channelId=12345, id=12345, tag=null, opPkg=xxx.xxx.xxx, callingUid=10085, userId=0, incomingUserId=0, notificationUid=10085, notification=Notification…
跟进NotificationManager的notify方法,调用了NotificationManagerService的enqueueNotificationWithTag将通知入队,最后在NotificationManagerService的enqueueNotificationInternal方法中发现了error log的踪迹,截取代码片如下图:
见图可知,是由于此条通知没有查找到应用中对应的NotificationChannel的原因,而无法

本文介绍了Android O中新增的通知渠道(NotificationChannel)特性,以及如何处理因未正确设置channelId导致的通知无法弹出的问题。通过创建和管理NotificationChannel,可以为用户提供自定义的通知设置,提高用户体验。同时,文章提供了创建、发送和删除NotificationChannel的示例代码。

1万+

被折叠的 条评论
为什么被折叠?



