You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter中使用Awesome Notifications包提示无效通知(无有效小图标)

Flutter Awesome Notifications 无效通知问题解决

报错信息

E/Android: Awesome Notifications: Invalid notification (no valid small icon): Notification(channel=basic_channel shortcut=null contentView=null vibrate=null sound=null tick defaults=0x0 flags=0x11 color=0xff009688 vis=PRIVATE) (NotificationThread:58)
W/System.err(25254): me.carda.awesome_notifications.core.exceptions.AwesomeNotificationsException: Invalid notification (no valid small icon): Notification(channel=basic_channel shortcut=null contentView=null vibrate=null sound=null tick defaults=0x0 flags=0x11 color=0xff009688 vis=PRIVATE)
W/System.err(25254): at android.app.NotificationManager.fixNotification(NotificationManager.java:606)
W/System.err(25254): at android.app.NotificationManager.notifyAsUser(NotificationManager.java:585)
W/System.err(25254): at android.app.NotificationManager.notify(NotificationManager.java:534)
W/System.err(25254): at android.app.NotificationManager.notify(NotificationManager.java:510)
W/System.err(25254): at me.carda.awesome_notifications.core.managers.StatusBarManager.showNotificationOnStatusBar(StatusBarManager.java:86)
W/System.err(25254): at me.carda.awesome_notifications.core.threads.NotificationSender.showNotification(NotificationSender.java:260)
W/System.err(25254): at me.carda.awesome_notifications.core.threads.NotificationSender.doInBackground(NotificationSender.java:147)
W/System.err(25254): at me.carda.awesome_notifications.core.threads.NotificationSender.doInBackground(NotificationSender.java:32)
W/System.err(25254): at me.carda.awesome_notifications.core.threads.NotificationThread.runOnForegroundThread(NotificationThread.java:106)
W/System.err(25254): at me.carda.awesome_notifications.core.threads.NotificationThread.execute(NotificationThread.java:34)
W/System.err(25254): at me.carda.awesome_notifications.core.threads.NotificationSender.send(NotificationSender.java:101)
W/System.err(25254): at me.carda.awesome_notifications.core.AwesomeNotifications.createNotification(AwesomeNotifications.java:569)
W/System.err(25254): at me.carda.awesome_notifications.AwesomeNotificationsPlugin.channelMethodCreateNotification(AwesomeNotificationsPlugin.java:1274)

问题原因

Android系统强制要求通知必须提供透明背景的单色小图标,当前通知未配置符合要求的小图标,导致系统拒绝显示。

解决步骤

1. 准备合规的小图标

  • 图标必须是透明背景,仅保留单色轮廓(建议白色),禁止使用彩色或不透明背景的图片。
  • 用Android Studio生成标准通知图标:右键android/app/src/main/res文件夹 → New → Image Asset → 选择Notification Icon类型,按向导完成生成,图标会自动分发到对应分辨率的drawable文件夹。

2. 在通知代码中指定小图标

创建通知时,通过icon参数填入图标名称(不带扩展名):

await AwesomeNotifications().createNotification(
  content: NotificationContent(
    id: 1,
    channelKey: 'basic_channel',
    title: '你的通知标题',
    body: '你的通知内容',
    icon: 'ic_notification_small', // 替换为你生成的图标名称
  ),
);

3. 配置通知渠道默认图标(可选)

初始化Awesome Notifications时,给通知渠道设置默认图标,确保该渠道下所有通知都能使用正确图标:

await AwesomeNotifications().initialize(
  null,
  [
    NotificationChannel(
      channelKey: 'basic_channel',
      channelName: '基础通知渠道',
      channelDescription: '用于显示常规通知',
      defaultIcon: 'ic_notification_small', // 渠道默认图标
    )
  ],
);

4. 清理缓存并重启项目

执行以下命令清理缓存,避免旧资源残留导致的问题,之后重新运行App:

flutter clean
flutter run

内容的提问来源于stack exchange,提问作者TarbiyaUz Khusanboev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 15:40:21