0

When Android App is in Foreground State, onPushNotificationReceived listener is getting invoked having the notification data. When in Background or Terminated State, Notification does get received but onPushNotificationReceived listener is not getting invoked neither automatically nor when I tap on the notification. I'm sending the push from Azure Portal.

{ "notification":{ "title":"Notification Hub Test Notification", "body":"This is a sample notification delivered by Azure Notification Hubs." }, "data":{ "property1":"value1", "property2":53 }, "priority": "high" }

I'm following Tutorial: Send push notifications to Android devices using Firebase SDK version 1.0.0-preview1 (Current SDK) tutorial. https://learn.microsoft.com/en-us/azure/notification-hubs/android-sdk

Android OS: 11

Is there something else which i need to do apart from the mentioned steps in the above link?

NotificationListener

AndroidManifest

MainActivity

Himanshu Ahuja
  • 197
  • 1
  • 13

1 Answers1

0

Make sure your app is in the background or closed then a notification message is shown in the notification center, and any data from that message is passed to the intent that is launched as a result of the user tapping on the notification.

When the intent is launched you can use the getIntent().getExtras();

onMessageReceived is provided for most message types, which follows

  • Notification messages delivered when your app is in the background. The notification is delivered to the device’s system tray. A user tap on a notification opens the app launcher by default.

  • Messages with both notification and data payload, when received in the background. The notification is delivered to the device’s system tray, and the data payload is delivered in the extras of the intent of your launcher Activity.

Refer Handling response & Push notification in android to implement in your project.

You can use the .getInitialMessage() on FirebaseMessaging instance

FirebaseMessaging.instance
    .getInitialMessage()
    .then((RemoteMessage message) {
        if (message != null) {
            Navigator.pushNamed(context, message.data['view']);
    }
});

Refer here

Delliganesh Sevanesan
  • 4,146
  • 1
  • 5
  • 15