自定义通知声音在应用发布后不起作用

Custom notification sound not working after app release

提问人:十市将伍 提问时间:11/10/2023 最后编辑:President James K. Polk十市将伍 更新时间:11/10/2023 访问量:33

问:

我想使用自定义通知声音。 我编写了如下代码

      Future<void> _createNotificationChannel(String id, String name, String description, String sound) async {
        final flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
        var androidNotificationChannel = AndroidNotificationChannel(
          id,
          name,
          description: description,
          sound: sound == "default" ? null : RawResourceAndroidNotificationSound(sound),
          playSound: true,
        );

        await flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation<AndroidFlutterLocalNotificationsPlugin>()?.createNotificationChannel(androidNotificationChannel);
      }

      try {
        _createNotificationChannel("sos", "sos_channel", "緊急通報用", "new_sos_sound");
        _createNotificationChannel("claim", "claim_channel", "クレーム用", "new_claim_sound");
        _createNotificationChannel("default", "default_channel", "通常の通知", "default");
        print('************************* Success created notification channel *****************************');
      } catch (e) {
        print('*************************Error(createNotificationChannel): $e *****************************');
      }
async function pushToDevice(
  token: string,
  title: string,
  body: string,
  badgeCount: number,
  messageType: string
): Promise<void> {
  const pushMessage = (
    _token: string,
    _title: string,
    _body: string,
    _badgeCount: number,
    _messageType: string
  ): admin.messaging.TokenMessage => {
    return {
      token: _token,
      data: {
        metadata: "someMetadata",
        messageType: _messageType
      },
      notification: {
        title: _title,
        body: _body
      },
      android: {
        priority: "high",
        notification: {
          title: _title,
          body: _body,
          channelId:
            _messageType == "sos"
              ? "sos"
              : _messageType == "claim"
              ? "claim"
              : "default"
        }
      },
    }
  }



  await admin
    .messaging()
    .send(pushMessage(token, title, body, badgeCount, messageType))
}

在此处输入图像描述

这在使用真实设备进行“flutter run”测试时有效,但在应用程序发布后不起作用。

当我从设备设置屏幕检查时,我能够确认已创建通知频道。

在此处输入图像描述

我还可以确认为每个通道设置了自定义声音。

在此处输入图像描述

但是,我在设备设置屏幕上听不到自定义声音。 当我使用“flutter run”运行时,我可以从设备设置屏幕听到自定义声音。

我不知道问题出在哪里。

对不起,我的英语很差。 提前感谢您的帮助。

◎颤动医生

[√] Flutter (Channel stable, 3.13.3, on Microsoft Windows [Version 10.0.22000.2538], locale ja-JP)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.1.3)
[√] Android Studio (version 4.2)
[√] VS Code (version 1.84.2)
[√] Connected device (3 available)
[√] Network resources

我不知道问题出在哪里。

Android Flutter 推送 firebase-cloud-messaging 通知-频道

评论

0赞 Septian Dika 11/10/2023
用于测试开发环境和生产环境的设备是同一台设备吗?

答: 暂无答案