相关疑难解决方法(0)

Flutter:无法在 onBackgroundMessage 中使用任何插件

我正在使用 Firebase 推送通知,我想在触发 onBackgroundMessage 时执行我的一些代码。它实际上被触发,因为我在控制台中打印,但我尝试使用几个插件但没有运气。每次我都会收到类似(未处理的异常:MissingPluginException(在频道 flutter_ringtone_player 上找不到方法播放的实现))的错误。我相信这是因为在应用程序的后台状态中没有应用程序的上下文,但是这个功能有什么用,我实际上可以在其中做什么?

我想在触发 onBackgroundMessage 时播放声音。

    super.initState();

    _firebaseMessaging.configure(
      onMessage: (Map<String, dynamic> message) async {
        print("onMessage: $message");
      },
      onBackgroundMessage: myBackgroundMessageHandler,
      onLaunch: (Map<String, dynamic> message) async {
        print("onLaunch: $message");
      },
      onResume: (Map<String, dynamic> message) async {
        print("onResume: $message");
      },
    );

static Future<dynamic> myBackgroundMessageHandler(Map<String, dynamic> message) async {        
  FlutterRingtonePlayer.play(
    android: AndroidSounds.notification,
    ios: IosSounds.glass,
    looping: true, // Android only - API >= 28
    volume: 0.8, // Android only - API >= 28
    asAlarm: true, // Android only - all APIs …
Run Code Online (Sandbox Code Playgroud)

firebase flutter firebase-cloud-messaging

6
推荐指数
1
解决办法
6863
查看次数