How do I display the text of a notification when the user opens this notification?

Asked

Viewed 132 times

0

I’m creating an app with Phonegap and using cordova-plugin-firebase to send notifications to Android, I’m able to send the notification, but when I "open" the notification I can’t show its content (title and message)

window.FirebasePlugin.onNotificationOpen(function(notification) {
     alert(JSON.stringify(notification));
}, function(error) {
     console.error(error);
});

All that appears on Alert are:

google.sent_time
google.ttl
tap
from
google.message_id
google.priority
collapse_key

according to the image. inserir a descrição da imagem aqui Does anyone know how I can take the information and display it to the user?

  • You will probably use collapse_key or google.message_id to fetch the desired message.

  • But as I search, what I’m not finding, I saw in some videos that it comes together in the notification, but print in Alert and does not appear

1 answer

0


I managed, actually the problem was not in the app, but where I send the news, with the FCM need to send title and message to when the app is in foreground and other for when it is in the background, I was only sending from the foreground, so when received notification with the open app appeared, but not with the app closed, when opening by notification did not appear, I decided sending so

"to" : "<DEVICE TOKEN>"
, 
"notification": {
    "title": "This is used in the foreground",
    "body": "This is used in the foreground"
},
"data":{
      "title":"This is used in the background",
      "body":"This is used in the background"
}

according to this link https://github.com/arnesson/cordova-plugin-firebase/issues/431

Browser other questions tagged

You are not signed in. Login or sign up in order to post.