Notification Android8.0中无法发送通知,提示:No Channel found for pkg

用Android 8.0的手机进行发送通知的测试,发现通知不能在系统状态栏显示出来,查看Logcat,发现warning如下
No Channel found for pkg=com.example.xx.xx, channelId=null, id=1001, tag=null…

原来是由于此条通知没有查找到应用中对应的NotificationChannel的原因,而无法弹出来,查阅资料得知,NotificationChannel是Android O新增的通知渠道,其允许您为要显示的每种通知类型创建用户可自定义的渠道

如果你需要发送属于某个自定义渠道的通知,你需要在发送通知前创建自定义通知渠道,示例如下:

//ChannelId为"001",ChannelName为"my_channel"
NotificationChannel channel = new NotificationChannel("1",
                "my_channel", NotificationManager.IMPORTANCE_DEFAULT);
channel.enableLights(true); //是否在桌面icon右上角展示小红点
channel.setLightColor(Color.GREEN); //小红点颜色
channel.setShowBadge(true); //是否在久按桌面图标时显示此渠道的通知
notificationManager.createNotificationChannel(channel);

//同时,Notification.Builder需要多设置一个
builder.setChannelId("001");

一个完整的发送通知的栗子可以看
https://blog.csdn.net/u010356768/article/details/83382446

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值