android
runtime_error
ai_generated
true
NotificationManager:通知未显示,缺少频道。频道 'my_channel_id' 未创建。
NotificationManager: notification not shown, missing channel. Channel 'my_channel_id' was not created.
ID: android/notification-channel-missing
95%修复率
90%置信度
1证据数
2023-08-12首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| Android 8.0 (API 26) | active | — | — | — |
| Android 9 (API 28) | active | — | — | — |
| Android 10 (API 29) | active | — | — | — |
| Android 11 (API 30) | active | — | — | — |
| Android 12 (API 31) | active | — | — | — |
根因分析
在 Android 8.0+(API 26+)上发布通知前未创建通知频道,而频道是强制性的。
English
Notification channel not created before posting a notification on Android 8.0+ (API 26+), where channels are mandatory.
官方文档
https://developer.android.com/training/notifications/channels解决方案
-
Create channel before posting notification: `if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { val channel = NotificationChannel("my_channel_id", "My Channel", NotificationManager.IMPORTANCE_DEFAULT); notificationManager.createNotificationChannel(channel) }` -
Use `NotificationChannel` with a unique ID and call `createNotificationChannel()` in Application.onCreate() to ensure channel exists before any notification.
-
Check if channel exists before posting: `val channel = notificationManager.getNotificationChannel("my_channel_id"); if (channel == null) { createChannel() }`
无效尝试
常见但无效的做法:
-
Set targetSdkVersion below 26 to bypass channel requirement
90% 失败
Google Play requires targetSdkVersion 31+ for new apps; also, notifications still fail on API 26+ devices.
-
Use NotificationCompat.Builder without channel ID
85% 失败
NotificationCompat.Builder still requires a valid channel ID on API 26+; omitting it causes the same error.
-
Post notification from a Service instead of Activity
95% 失败
Service context doesn't bypass channel requirement; channel creation is still needed.