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

Flutter Android端FCM自定义通知声音无法正常工作求助

FCM自定义通知声音不生效排查方案
  • 检查音频文件命名与拼写
    确保res/raw下的文件名order_notification_sound.mp3全小写、无空格或特殊字符,且发送请求中sound字段的值(order_notification_sound)与文件名(不含后缀)完全一致——Android文件名区分大小写,拼写错误会导致无法识别资源。

  • 适配Android 8.0+通知通道
    Android 8.0及以上版本,FCM通知必须绑定通知通道,notification字段中的sound参数会被通道设置覆盖。需在餐厅端创建指定自定义声音的通知通道:

    // 以flutter_local_notifications插件为例
    const AndroidNotificationChannel orderChannel = AndroidNotificationChannel(
      'order_notification_channel_id', // 唯一通道ID
      '新订单通知', // 通道名称
      description: '接收客户下单通知的专用通道',
      importance: Importance.high,
      sound: RawResourceAndroidNotificationSound('order_notification_sound'),
    );
    
    // 初始化时创建通道
    final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
        FlutterLocalNotificationsPlugin();
    await flutterLocalNotificationsPlugin
        .resolvePlatformSpecificImplementation<
            AndroidFlutterLocalNotificationsPlugin>()
        ?.createNotificationChannel(orderChannel);
    

    同时在发送请求的notification字段中关联该通道:

    "notification": {
      "title": title,
      "body": message,
      "sound": "order_notification_sound",
      "android": {
        "channel_id": "order_notification_channel_id"
      }
    }
    
  • 确认FCM消息处理逻辑
    若餐厅端App处于后台或被杀死状态,系统会自动展示notification字段的通知,此时必须依赖通知通道的声音配置;若App处于前台,需确保自定义通知展示逻辑中指定了正确的声音资源。

  • 验证音频文件有效性
    检查order_notification_sound.mp3文件是否损坏,编码是否符合Android支持的格式(MP3/WAV/OGG),可通过MediaPlayer在餐厅端App内测试播放该文件,确认文件本身无问题。

  • 检查发送请求参数
    确保请求priority设为high(已设置),避免因低优先级导致通知处理异常;同时确认to字段的设备令牌(token)正确对应餐厅端目标设备。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.08 10:25:03