Skip to content
This repository was archived by the owner on Feb 7, 2019. It is now read-only.
This repository was archived by the owner on Feb 7, 2019. It is now read-only.

Data not being received in intent either in launching activity or application #175

Open

Description

@reytum

When a notification from tray is clicked the app launches but no data is received in the intent. I have tried receiving the data in app.ts and my first view classes, for the events launchEvent and resumeEvent, but the data is received as empty whereas i am getting the data in onMessageReceived callback (stringified data).

here's the login.js file'c code

   application.on(application.launchEvent, function(args) {
        var act = args.android;
         if (act) {
           var intent = act.getIntent();
           var extras = intent.getExtras();
           console.log("*****Received intent login : " + JSON.stringify(intent));
           console.log("*****Received extras login : " + JSON.stringify(extras));
          
         if (extras) {
              console.log("*****Received intent login : " + JSON.stringify(intent));
              console.log("*****Received extras login : " + JSON.stringify(extras));
          }
      }
    });

everything in this is coming as empty.

This is my onMessageReceievd callback code:

 pushPlugin.onMessageReceived(function callback(stringifiedData, fcmNotification) {
      var notificationBody = fcmNotification && fcmNotification.getBody();
      console.log("*********Recieved message from plugin : " + stringifiedData);
      //console.log("Message received!\n" + notificationBody + "\n" + fcmNotification.getTitle());
      console.log("Notification received!\n" + JSON.stringify(fcmNotification));
    });

And this is what is prints:

*********Recieved message from plugin : {"APPLOZIC_21":"{\"id\":\"11c59dc62877c832883a1cdde60217a20\",\"type\":\"APPLOZIC_21\",\"message\":236838,\"notifyUser\":true,\"totalUnreadCount\":0,\"sendAlert\":false,\"messageMetaData\":{}}","foreground":true}
JS: Notification received!
JS: null

The other issue is that the notification is received only a few time, when the app is in background. It happens randomly. Sometime the notification is received, sometimes it is not.

Activity

  1. lini commented on Jan 4, 2018

    @lini
    Contributor

    You should use the application's resume event instead of launch to handle the received notification. Take a look at the demo app's code for the push plugin on how exactly to extract the data from the intent:

    app.on(app.resumeEvent, function(args) {

  2. jogboms commented on Jan 4, 2018

    @jogboms

    @reytum do you currently have any launchMode configuration in your manifest?

  3. reytum commented on Jan 4, 2018

    @reytum
    Author

    @jogboms I dont have any launch mode configured in Manifest, if you are referring to NativeScriptActivity.
    @lini I have tried the similar configuration in app.ts file as mentioned in the original question. But still getting the data as empty.

  4. lini commented on Jan 5, 2018

    @lini
    Contributor

    Please give us a sample of the notification payload you use. For example, I am testing with the following:

    {
        "notification": {
            "title": "My title",
            "text": "My text",
            "badge": "1",
            "sound": "default"
        },
        "data": {
            "foo": "bar"
        },
        "priority": "High",
        "to": "FCM_DEVICE_TOKEN"
    }
    

    I am seeing both the notification details (My title/My text) in the notification tray and when I tap on the notification and open the app, I am seeing the data there as well:

    01-05 13:49:50.497: V/JS(9210): If your notification has data (key: value) pairs, they will be listed here:
    01-05 13:49:50.498: V/JS(9210): google.sent_time: 1515152971335
    01-05 13:49:50.498: V/JS(9210): foo: bar
    01-05 13:49:50.498: V/JS(9210): from: 424050927453
    01-05 13:49:50.498: V/JS(9210): google.message_id: 0:1515152971339391%0ce8d8740ce8d874
    01-05 13:49:50.498: V/JS(9210): collapse_key: org.nativescript.ppTest
    

    I am using the demo app from this repo and an Android 7.1.1 (API 25) device to test.

  5. reytum commented on Jan 10, 2018

    @reytum
    Author

    @lini @jogboms Well we are using GCM's Message Builder to construct the payload in the backend. This is what we are receiving on the device side:

    {  
       "data" : {
        "message" :  "{  
          "id":"3002d7f24542aab636d966231fbb1b99b",
          "type":"APPLOZIC_01",
          "message":{  
             "key":"4-null-1515571377786",
             "userKey":"03bd75b9-c1c0-4ea7-9a0f-f26325f7c752",
             "to":"reytum2",
             "contactIds":"reytum2",
             "message":"sdvfva",
             "sent":false,
             "delivered":false,
             "read":false,
             "deliveredValue":0,
             "sendToDevice":false,
             "shared":false,
             "createdAtTime":1515571377827,
             "createdAt":"Jan 10, 2018 8:02:57 AM",
             "type":4,
             "source":5,
             "status":0,
             "pairedMessageKey":"5-null-1515571377786",
             "applicationKey":"agpzfmFwcGxvemljchgLEgtBcHBsaWNhdGlvbhiAgICAuqiOCgw",
             "contentType":0,
             "senderName":"reytum1",
             "metadata":{  
    
             },
             "alert":true
          },
          "notifyUser":true,
          "totalUnreadCount":4,
          "sendAlert":true,
          "messageMetaData":{  
    
          }
       }" //this is stringified
    },
    "notification" : {
        "title" : "sdkjd",
        "body" : "hey thjbsd"
    },
    "to" : "token"
    }
    

    The notification is being constructed in the tray, but the data is not being received in the intent.
    However, in onMessageReceived callback function I am getting the stringified data and the respective notification values.

    This is what I am using to receive the intent in app.ts file

    import "./bundle-config";
    import * as application from 'tns-core-modules/application';
    //application.start({ moduleName: "main-page" });
    application.on(application.resumeEvent, function(args) {
        // console.log("*****Received act  : " + JSON.stringify(act));
        //     console.log("*****Received intent  : " + JSON.stringify(intent));
        //     console.log("*****Received extras : " + JSON.stringify(extras));
        if (args.android) {
            //var intent = act.getIntent();
            const act = args.android;
            const intent = act.getIntent();
            const extras = intent.getExtras();
            //console.log("*****Received act  : " + JSON.stringify(act));
            console.log("*****Received intent login : " + JSON.stringify(intent));
            console.log("*****Received extras login : " + JSON.stringify(extras));
            if (extras) {
                // for (var key in extras) {
                //     console.log(key + ' -> ' + extras[key]);
                // }
                console.log("*****Received intent login : " + JSON.stringify(intent));
                console.log("*****Received extras login : " + JSON.stringify(extras));
            }
        }
      });
    application.start({ moduleName: "views/login/login" });
    
  6. reytum commented on Feb 1, 2018

    @reytum
    Author

    @lini @jogboms Any update on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions