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

Flutter推送FCM通知时Android端显示空白图标问题

FCM通知显示空白方形图标问题解决办法

以下是几个常见的排查和解决方向:

  • 图标格式与尺寸不达标
    Android通知图标要求是透明背景的单色矢量图(优先用VectorDrawable),带彩色或不透明背景的图片会被系统自动处理成空白方块。同时要覆盖不同dpi的尺寸:mdpi(24x24)、hdpi(36x36)、xhdpi(48x48)、xxhdpi(72x72)、xxxhdpi(96x96),分别放在res/drawable-xxx对应目录下。

  • 推送Payload配置错误
    后台发送通知时,notification字段里的icon要指定正确的资源名称(不带后缀,比如ic_notification而非ic_notification.png)。示例Payload:

    {
      "notification": {
        "title": "新通知",
        "body": "这是一条测试通知",
        "icon": "ic_notification"
      },
      "to": "设备推送Token"
    }
    

    如果用data类型消息,需要在客户端FirebaseMessagingService的onMessageReceived里手动设置图标:

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
            .setSmallIcon(R.drawable.ic_notification)
            .setContentTitle(messageData.get("title"))
            .setContentText(messageData.get("body"));
    
  • Android版本适配问题

    • Android 8.0+(API26)必须创建通知渠道,若渠道图标设置错误也会导致异常。创建渠道时可指定图标:
      NotificationChannel channel = new NotificationChannel(CHANNEL_ID, "通知渠道", NotificationManager.IMPORTANCE_DEFAULT);
      channel.setIcon(R.drawable.ic_notification);
      NotificationManager manager = getSystemService(NotificationManager.class);
      manager.createNotificationChannel(channel);
      
    • Android 5.0-7.1系统会自动将通知图标转为白色(深色状态栏)或黑色(浅色状态栏),非透明单色图会直接显示空白。
  • 资源文件问题
    通知图标不能放在mipmap目录(该目录用于启动器图标),必须放在drawable目录下;同时注意资源名称大小写敏感,避免拼写错误。

  • 缓存问题
    设备可能缓存了旧图标,尝试重启设备或卸载重装应用,清除缓存后再测试。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 20:45:57