无法在频道上发布通知“null”目标Api是26 [英] Failed to post notification on channel "null" Target Api is 26
问题描述
两个日志显示
1:对于音量控制以外的操作,不推荐使用流类型
2:请参阅setSound()的文档以代替使用android.media.AudioAttributes来限定您的播放用例
如果遇到这个错误,应该注意3个项目:
-
builder = new NotificationCompat.Builder(this,name);
-
builder.setChannelId(id)// Android 8需要Oreo API 26及更高版本
错误的原因不符合所有三个要素。
只有必要的setter
builder.setContentTitle()//必需
.setSmallIcon在Android 8 Oreo API 26及更高版本上的通知列表()//需要
.setContentText()//需要
.setChannelId(id)//在Android 8上需要Oreo API 26及更高版本
请参阅在Android 8上,奥利奥API 26和更高版本的通知不会显示。
Two log showing
1: Use of stream types is deprecated for operations other than volume control
2: See the documentation of setSound() for what to use instead with android.media.AudioAttributes to qualify your playback use case
If you get this error should be paid attention to 3 items:
builder = new NotificationCompat.Builder(this, name);
NotificationChannel mChannel = new NotificationChannel(id, name, importance);
builder.setChannelId(id) // required for Android 8 Oreo API 26 and later
The reason for the error not in compliance with all three elements.
There are only required setters list for Notification on Android 8 Oreo API 26 and later:
builder.setContentTitle() // required
.setSmallIcon() // required
.setContentText() // required
.setChannelId(id) // required on Android 8 Oreo API 26 and later
See the example in On Android 8 Oreo API 26 and later notification does not display.
这篇关于无法在频道上发布通知“null”目标Api是26的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!