FCM get data after Tap

Using the FCM plugin here I am getting the notifications using firebase.

 let ready=await this.platform.ready();
         },(error)=>{console.log(`error ${error}`);

The notifications arrive when the app is not running and are also handled properly when the app is running.

But tapping the notification when the app is closed just opens the app.

I want to know how can I code the functionality that when the notification is tapped custom action is taken bases on the payload received.

I do it inside the app.component.ts constructor:

  constructor(fcm: FCM) {

  platform.ready().then(() => {

    fcm.onNotification().subscribe(data => {
      if (data.wasTapped) {
        // Here the app was closed and the notification opened the app.
        this.navCtrl.setRoot('ClientDetailPage', { clientId: data.clientId });
      } else {
        // Here the notification arrived when the app was opened, 
        // so won't appear in the system tray.

Can you double check this. I am not getting any data have tested this thoroughly.

It’s working, what does your payload object look like in the server? One thing I can think of is to check you’re sending the click_action in it.

For example, I have an app that sends a notification to a fitness coach every time his clients update their weight, my payload looks like this:

const payload = {
	notification: {
	  title: `${clientName} just shared a weight update`,
	  body: `${clientName} started at ${clientStartingWeight} and 
             just updated to ${weight}`,
	  sound: 'default',
	  click_action: 'FCM_PLUGIN_ACTIVITY'
  data: { 
  	clientId: clientId 

Yes, I read that in the docs as well about the click_action. I am sending notifications using the firebase dashboard and to my knowledge, it does not have any option to set the click_action.

I’d say try sending them from Cloud Functions or your own server to test, I think the plugin page has a test server that works.

where do you place this??? in what part?

I would suggest downloading postman (its free) and writing your own post request for testing.

You will need to:

  1. set the url to https://fcm.googleapis.com/fcm/send
  2. set the Autorization header of the request to key=<your_key_here> (you can get your key from the firebase console)
  3. Set the request to POST
  4. set the body of the request to bo something like this:

“to” : “device_token”,
“collapse_key” : “type_a”,
“notification” : {
“body” : “Body here”,
“title”: “a title here”,