FirebaseMessaging.onMessage.listen() only working for Notification messages
All we had to do was add
message.put("content_available", true);
to the end of our message JSONObject.
Further information can be found here.
Frank van Puffelen
I am an engineer for Firebase at Google. I respond equally well to being called "Frank" or "puf".
Updated on December 30, 2022Comments
-
Frank van Puffelen over 1 year
I am currently working on an application for iOS where I want to send push notifications through Firebase's Cloud Messaging console, and send notifications through https://fcm.googleapis.com/fcm/send via a Java http request. I created an onMessage listener shown here:
FirebaseMessaging.onMessage.listen((RemoteMessage message) { print("onMessage listener fired"); if (message != null) { PersonalFirebase.onMessageReceived(message, context, setState, flutterLocalNotificationsPlugin, notificationSettings.authorizationStatus); } });
This listener is successfully fired if I send a message through the Firebase console in my project, however nothing happens if I attempt to send a data message through an HTTP request even when I get a 200 response code. For reference, here is the payload I am sending to the http request in Java:
JSONObject values = new JSONObject(); values.put("action", "show_message"); values.put("title", "showMessageFunction"); values.put("message", "Testing showMessage function"); values.put("channel", "1"); JSONObject parentData = new JSONObject(); parentData.put("data", values); JSONObject message = new JSONObject(); message.put("to", to); message.put("data", parentData);
Basically my question is as follows: does FirebaseMessaging.onMessage only work for Notifications sent through the Firebase console. If so, is there an alternative to FirebaseMessaging.onMessage for data messages through a https://fcm.googleapis.com/fcm/send http request?
Let me know if there is anything else I can add to help.