1
votes

I have a problem with the reception of notifications when the origin is Azure, through Azure Notification Hubs. I followed the steps of this tutorial: https://developer.xamarin.com/guides/android/application_fundamentals/notifications/remote-notifications-with-fcm/

At this time, after some problems with nuget dependencies conflict, I received correctly the notifications through the Firebase Console. However the "Test Send" option of Azure Notification Hubs seems to send the message but the device do not receive the notification.

Following this other tutorial to send Azure notifications with FCM Service https://docs.microsoft.com/en-us/azure/notification-hubs/notification-hubs-android-push-notification-google-fcm-get-started, some steps seems not to be possible in Xamarin.Android, like adding dependences in build.gradle.

How is it possible to incorporate those changes in a Xamarin.Android project?

1

1 Answers

1
votes

Gerard,

The way you'll get the content of your message is different when sending from the Firebase console and the Test Send option in Azure Notification Hubs.

As you saw in the Xamarin turorial with FCM, to get the message content we do the following:

public override void OnMessageReceived(RemoteMessage message)
{
    Log.Debug(TAG, "From: " + message.From);
    Log.Debug(TAG, "Notification Message Body: " + message.GetNotification().Body);
}

However it will not work when using Test Send because GetNotification() will be null.

When using Test Send we are sending the following Payload:

{"data":{"message":"Notification Hub test notification"}}

Now how to get your message? If you take a look at RemoteMessage you will notice the following Data property: public IDictionary<string, string> Data { get; }.

You'll be able to retrieve your message using the Data property as shown bellow:

public override void OnMessageReceived(RemoteMessage remoteMessage)
{
    Log.Debug(TAG, "From: " + remoteMessage.From);

    if (remoteMessage.Data.ContainsKey("message"))
    {
        Log.Debug(TAG, "Notification Message: " + remoteMessage.Data["message"]);
    }
}