如何解决Flutter Background Service通知图标与应用图标不一致问题
Flutter flutter_background_service 后台通知图标修复方案
Android 平台修复步骤
准备符合规范的通知图标
Android 通知图标要求为透明背景的单色(建议白色)图标,需适配不同分辨率,将图标文件(如ic_notification.png)放置在android/app/src/main/res/mipmap-*或drawable-*对应分辨率目录下。在服务配置中指定图标
配置flutter_background_service时,在AndroidConfiguration里明确设置notificationIcon参数,值为图标文件名(不带后缀):await FlutterBackgroundService().configure( androidConfiguration: AndroidConfiguration( onStart: onStart, autoStart: true, isForegroundMode: true, notificationIcon: 'ic_notification', // 图标文件名(无后缀) notificationChannelId: 'my_background_channel', notificationTitle: '后台服务运行中', notificationContent: '正在执行后台任务', ), // iOS 配置... );注意事项
- 若直接使用应用图标,需确保应用图标本身符合单色透明要求,否则系统会自动将其处理为白色剪影,导致显示异常。
- Android 8.0+ 中,通知渠道创建后无法修改图标属性,若之前已创建渠道,需卸载应用后重新安装生效。
- 执行
flutter clean清理缓存后重新构建项目,避免旧资源残留。
iOS 平台修复步骤
配置通知图标资源
在Assets.xcassets中创建NotificationIcon图标集,添加对应尺寸的透明背景图标,符合iOS通知图标规范。在服务配置中指定图标
在IosConfiguration里设置notificationIcon参数为图标集名称:iosConfiguration: IosConfiguration( onForeground: onStart, onBackground: onIosBackground, autoStart: true, notificationIcon: 'NotificationIcon', // 图标集名称 ),开启后台权限
在Info.plist中添加后台模式权限:<key>UIBackgroundModes</key> <array> <string>fetch</string> <string>remote-notification</string> </array>
内容的提问来源于stack exchange,提问作者Salar Azad
相关产品推荐
相关产品推荐

