我已将 flutter_local_notifications 与我的应用程序集成,并且在开发过程中它与 iOS 和 Android 配合得很好。但是,我注意到发布的 Android 应用程序没有显示通知。好像是我设置的自定义通知图标导致的。
const AndroidInitializationSettings initializationSettingsAndroid =
AndroidInitializationSettings('ic_notification');
看起来相关的 logcat:
08-30 08:33:23.291 2423 2423 E Icon : Unable to load resource 0x7f06007f from pkg=com.example.package
08-30 08:33:23.291 2423 2423 E Icon : android.content.res.Resources$NotFoundException: Drawable com.example.package:drawable/ic_notification with resource ID #0x7f06007f
08-30 08:33:23.291 2423 2423 W StatusBarIconView: No icon for slot com.example.package/0x79716; Icon(typ=RESOURCE pkg=com.example.package id=0x7f06007f)
如果我将
ic_notification
替换为 @mipmap/ic_launcher
,一切都会按预期进行。
我按照官方说明创建了图标,并将
ic_notification.png
放置在我的Android项目中,如下所示:
android/app/src/main/res/
├── drawable
│ ├── ic_launcher_background.xml
│ └── launch_background.xml
├── drawable-anydpi
│ └── ic_notification.xml
├── drawable-hdpi
│ └── ic_notification.png
├── drawable-mdpi
│ └── ic_notification.png
├── drawable-v21
│ └── launch_background.xml
├── drawable-xhdpi
│ └── ic_notification.png
├── drawable-xxhdpi
│ └── ic_notification.png
我以为这就是我所要做的,但我错过了什么?我猜这应该与我的构建配置有关,因为该问题仅在发布版本中观察到。
通知图标图像必须是透明的。问题可能是由于背景造成的 [https://www.remove.bg/upload][1]
在此处上传您的图像,删除背景,然后尝试
你也可以关注这个帖子
[https://stackoverflow.com/questions/57362439/notification-icon-doesnt-show-in-flutter-android-app-local-notification-flutter][2]