I am using Firebase Push Notifications and I want to execute some of my code when onBackgroundMessage is triggered. It actually gets triggered because I print in console, but I tried to use several plugins and no luck. I get error every time something like (Unhandled Exception: MissingPluginException(No implementation found for method play on channel flutter_ringtone_player)). I believe this is because there is no context of application in background state of application, but what is this function good for then and what can I actually do in it?
I would like to play sound when onBackgroundMessage is triggered.
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
);
print("background message executed");
return null;
}