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

Flutter创建Android通知channel后FCM推送无声音振动如何解决?

问题原因与解决方案

核心原因

Android 8.0及以上系统中,通知频道的属性一旦创建就会被系统持久化缓存,后续重复调用创建接口无法修改原有属性;且默认配置下仅设置importance: Importance.max不会自动启用声音和振动,需要显式声明相关参数。


具体修复步骤

1. 补全通知频道创建的音效振动参数

修正你的channel创建代码,显式开启声音、振动配置:

import 'dart:typed_data';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';

// ...
await FlutterLocalNotificationsPlugin()
  .resolvePlatformSpecificImplementation<
      AndroidFlutterLocalNotificationsPlugin>()
  ?.createNotificationChannel(AndroidNotificationChannel(
    'high_importance_channel', // id
    'High Importance Notifications', // title
    description: 'This channel is used for important notifications', // description
    importance: Importance.max,
    // 新增音效振动相关配置
    enableVibration: true,
    vibrationPattern: Int64List.fromList([0, 1000, 500, 1000]), // 自定义振动节奏:延迟0ms、振1000ms、停500ms、振1000ms
    playSound: true,
    sound: AndroidNotificationSound.default, // 调用系统默认通知音,也可传入自定义音频资源
  ));

注意:修改channel参数后必须完全卸载原有应用再重新安装,否则系统会沿用旧的channel缓存配置,新参数不生效。

2. 校验FCM推送payload配置

确保服务端发送FCM通知时,安卓配置节点正确匹配你创建的channel id,不要添加覆盖音效振动的参数:

{
  "message": {
    "token": "用户设备fcm令牌",
    "android": {
      "priority": "high",
      "notification": {
        "channel_id": "high_importance_channel", // 必须和创建的channel id完全一致,区分大小写
        // 不要添加 sound: null、vibrate_timings: [] 这类会关闭音效振动的参数
      }
    },
    "notification": {
      "title": "通知标题",
      "body": "通知内容"
    }
  }
}

3. 校验系统频道开关配置

进入设备的应用设置→通知管理→找到当前应用→找到你创建的「High Importance Notifications」频道,确认声音、振动开关均处于开启状态。如果开关灰掉无法修改,卸载重装应用即可恢复可配置状态。

4. 前台自定义通知展示校验

如果应用在前台接收FCM通知时,是手动调用FlutterLocalNotificationsPlugin.show()方法展示通知,需要确保调用时的安卓配置参数指定了对应channel id:

await FlutterLocalNotificationsPlugin().show(
  通知id,
  '标题',
  '内容',
  NotificationDetails(
    android: AndroidNotificationDetails(
      'high_importance_channel', // 必须匹配创建的channel id
      'High Importance Notifications',
      // 其他配置
    ),
  ),
);

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.30 10:48:04