内推
【长期有效】欢迎加入字节跳动我的团队:内推链接
从一个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的踪迹,截取代码片如下图: