fechanique / cordova-plugin-fcm

Google FCM Push Notifications Cordova Plugin
623 stars 998 forks source link

Message in foreground on android has no text only "wasTapped:false" #89

Open PhilCorcoran opened 8 years ago

PhilCorcoran commented 8 years ago

Using your code example on Android (Samsung Galaxy S5 Marshmallow) the device tray correctly shows the text when the app is in the background. However the same message sent when the app is open has no text. When the data object is stringified it is simply "wasTapped:false" Maybe google's API has changed?

FCMPlugin.onNotification(
  function(data){
    if(data.wasTapped){
      //Notification was received on device tray and tapped by the user.
      alert( JSON.stringify(data) );
    }else{
      //Notification was received in foreground. Maybe the user needs to be notified.
      alert( JSON.stringify(data) );
    }
  });
delsoul6104 commented 8 years ago

me too....

benlooi commented 8 years ago

I did not use JSON.stringify(data). Instead, I used alert(data.notification.body);

santoshtechwiz commented 8 years ago

Me too...

IgnazioSammarco commented 8 years ago

Me too

wajdibr commented 7 years ago

Guys i had the same problem. It's only happening when you're in the foreground (using your app). It's because Push Notification with use Data array and not notification array. As a native android developer i've modified it in the class MyFirebaseMessagingService inside my project, method onMessageReceived. You will find those lines : Map<String, Object> data = new HashMap<String, Object>(); data.put("wasTapped", false); I've changed it this way: Map<String, Object> data = new HashMap<String, Object>(); data.put("wasTapped", false); data.put("title", remoteMessage.getNotification().getTitle()); data.put("body", remoteMessage.getNotification().getBody()); I think that you can post message inside Data array from your server and that is another solution i've not tried yet. Hope it will help.

Regards.

PhilCorcoran commented 7 years ago

@wajdibr can you submit that change as a pull request?

wajdibr commented 7 years ago

I will try to push it as soon as i can Phil. Waiting for my pull, can you change your server to put a message attribute inside the data array ? It should solve the problem. Regards.

PhilCorcoran commented 7 years ago

Thanks Ben

On Tue, Nov 1, 2016 at 11:12 AM, Ben Rabah Wajdi notifications@github.com wrote:

I will try to push it as soon as i can Phil. Waiting for my pull, can you change your server to put a message attribute inside the data array ? It should solve the problem. Regards.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/fechanique/cordova-plugin-fcm/issues/89#issuecomment-257541639, or mute the thread https://github.com/notifications/unsubscribe-auth/ABZq7ha8l7BfjOAk8cm7u7XxtGssr2rcks5q5x6UgaJpZM4JwRb1 .

wajdibr commented 7 years ago

@PhilCorcoran the pull request is here https://github.com/fechanique/cordova-plugin-fcm/pull/160 Hope it will solve this issue.

Regards.

PhilCorcoran commented 7 years ago

Thks

On 1 Nov 2016 9:58 PM, "Ben Rabah Wajdi" notifications@github.com wrote:

@PhilCorcoran https://github.com/PhilCorcoran the pull request is here

160 https://github.com/fechanique/cordova-plugin-fcm/pull/160

Hope it will solve this issue.

Regards.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/fechanique/cordova-plugin-fcm/issues/89#issuecomment-257711346, or mute the thread https://github.com/notifications/unsubscribe-auth/ABZq7h-pLEINAtIxOoWGZwpH3YtSHWMaks5q57X2gaJpZM4JwRb1 .

juanmlf commented 7 years ago

@wajdibr answer is a way to do it, another way is that you set the key/value when you form the notification in the server. For example, i'm using the Firebase Console to test the notifications. When i compose a message in the Firebase Console i have the Extra Data or Customized Data that allows me to put the following key/values: Key: Value Title: Alarm Temperature: 30°C Humidity: 67%

When i receive the notification, my data array have all the information i added in the console. data Object {Humedity: "67%", Temperature: "30°C", wasTapped: false}

I expect these helps somebody (sorry for my english)

wajdibr commented 7 years ago

@PhilCorcoran Can you tell us if the problem was resolved or not ? So we can mark this one as resolved in that case. Thank you.

PhilCorcoran commented 7 years ago

We had to move ahead with a different solution. If I have time I will recreate it to verify

sourcebits-jayaprakash commented 7 years ago

We are having same problem, There is no foreground notification when App is open and even when we set the notification details as shown below: //POST: https://fcm.googleapis.com/fcm/send //HEADER: Content-Type: application/json //HEADER: Authorization: key=AIzaSy*** { "notification":{ "title":"Notification title", //Any value "body":"Notification body", //Any value // "sound":"default", //If you want notification sound "click_action":"FCM_PLUGIN_ACTIVITY", //Must be present for Android // "icon":"fcm_push_icon" //White icon Android resource }, "data":{ "title":"Notification title", //Any value "message":"Notification body", //Any value "param1":"value1", //Any data to be retrieved in the notification callback "param2":"value2", }, // "to":"/topics/topicExample", //Topic or single device // cordova-plugin-fcm specific target topic "to":"/topics/all", "priority":"high", //If not set, notification won't be delivered on completely closed iOS app // "restricted_package_name":"" //Optional. Set for application filtering }

We are at last week of releasing the product kindly please let us know the solution.

For iOS we get both the notification i.e. when app is in background and when it is in foreground.

Please provide the patch and solution for this bug.

Belio commented 6 years ago

Any news? We have the same problem with foreground notifications.

vaskea commented 6 years ago

I was also having this problem - not receiving notifications on android when app was in foreground. For me it was and issue with double push plugins installed. I had both phonegap-plugin-push and FCMPlugin installed. Checked installed plugins with: ionic cordova plugin and removed phonegap-plugin-push with: ionic cordova plugin rm phonegap-plugin-push

It was weird because it was working fine on ios and on background android. Hope this helps someone.

krisgale-zz commented 6 years ago

"click_action": "FCM_PLUGIN_ACTIVITY"

adding this to the notification object worked for me.

in both cases -- of either a tapping on a notification received to my phone's notification pane, or while the app was active in the foreground -- the data available to the app on receipt was any key/value pairs in the data object i had also sent, as well as: from, collapse_key, google.message_id and wasTapped... so, the notification object is strictly for use by the device notification pane -- that data will not propagate to FCMPlugin.onNotification.