EenPOOL
EenPOOL

Reputation: 1

Azure Notification Hub FCMv1 Cordova Android - background notification does not trigger on('notification')

Setup:

All works fine when the application is open in the foreground

The problem: When Push Notification received in background (application not on foreground), then click on push notification from notification center => does not trigger on('notification', function(data) { })

It's opening the application, without the trigger


NotificationTemplate for FCMv1:

{
  "message": {
    "notification": {
      "title": "$(title)",
      "body": "$(message)"
    },
    "data": {
      "notId": "$(notificationId)",
      "content-available": "$(contentAvailable)"
    },
    "android": {
      "notification": {
        "click_action": "com.adobe.phonegap.push.background.MESSAGING_EVENT"
      }
    }
  }
}

The sender:


var notification = new Dictionary<string, string>
{
    { "message", "my message"},
    { "title", "my title" },
    { "notificationId", "123456" },
    { "contentAvailable", "1" }
};

await hub.SendTemplateNotificationAsync(notification, "a specific tag");

Error when clicked on the notification from notification center:

Key notId expected Integer but value was a java.lang.String. The default value 0 was returned. 2024-06-14 23:35:39.508 11606-11606 Bundle com.my.bundle W Attempt to cast generated internal exception: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer at android.os.BaseBundle.getInt(BaseBundle.java:1077) at com.adobe.phonegap.push.PushHandlerActivity.onCreate(PushHandlerActivity.kt:36) at android.app.Activity.performCreate(Activity.java:8207) at android.app.Activity.performCreate(Activity.java:8191) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3819) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4022) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2336) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:246) at android.app.ActivityThread.main(ActivityThread.java:8653) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)


My guess is going to the notificationTemplate I'm using? Specifically the "notId" property

//I have tried all of those possibilities

"data": {
  "notId": "$(notificationId)", // background (see above error), foreground OK
},

"data": {
  "notId": "$('123456')", // background (see above error), foreground OK
},  

"data": {
  "notId": "$(123456)", // notification not arriving
}, 

"data": {
  "notId": "#(notificationId)", //notification not arriving 
}, 

"data": {
  "notId": "#(132456)", //notification not arriving 
}, 

"data": {
  "notId": #(notificationId), //error while registrering template
},

"data": {
  "notId": #(132456), //error while registrering template
},

To make it crazier... it all worked with the "normal" FCM, even more.. the notId was a GUID

Upvotes: 0

Views: 89

Answers (0)

Related Questions