Azure Hub notification cannot send to FCM

Hello. Excuse me for my poor english.

I have a problem with the reception of notifications when the origin is Azure, through Notification Hub Azure. 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 for nuget dependences conflict, I received correctly the notifications through the Firebase Console. But the "Test Send" option of Azure Hub Notification seems send the message but the device not receive the notification. Following this another tutorial for send Azure notifications with FCM Service
https://docs.microsoft.com/en-us/azure/notification-hubs/notification-hubs-android-push-notification-google-fcm-get-started
exists some steps seems not possible in Xamarin.Android, like add dependences in build.gradle. Some knows how it's possible incorporate this changes in Xamarin.Android project?

regards.

Answers

  • MKielblockMKielblock USMember

    @Gnalis , Have you made any head way with this, I have exactly the same problem, can send Messages to the devise from the FCM console, but not from the Azure Notification Hub 'Test Send' option.
    I have tried setting up the GCM service with using the Server key & the Legacy server key, but having no luck.

    Regards

  • MaciejBogutaMaciejBoguta USMember

    bump up - messages sent via both FCM console and raw http requests are delivered instantly, while Azure fails to even give me an error response from google

  • TimSTimS DEMember ✭✭

    Any updates on this? I'm facing the same issue...

  • DavidTrianaDavidTriana USUniversity

    I got Android background notifications working, both from the FCM console and from the Azure Notification Hub Test send function.

    To make it work I had to:

    1.Send a TAG on the .Register method of the NotificationHub
    2.Use a "notifications" template for the message payload, ref: https://developers.google.com/cloud-messaging/concept-options#notifications_and_data_messages , example:

    {
    "notification" : {
        "body" : "FINALLY",
        "title" : "It works"
        }
    }
    
  • Wow! I spent hours on this. Yes, I did NOT have to mess with tags since the feedback I got from the Test Send in the azure portal verified it was finding a device to send to. I ONLY had to do number 2 above and just change the format of the notification from the default data style to the notification style and SUCCESS!

  • alex-alexalex-alex USMember
    edited September 2017

    I still can't receive message from Azure even with notification template.
    Can send/receive message with Firebase console, but can't with Azure test send.
    In my Xamarin.Forms application I have add:

    FirebaseMessaging.Instance.SubscribeToTopic("news"); 
    

    But even with topic and notification have no luck. Still trying to figure what is wrong

  • programmerhammerprogrammerhammer BYMember ✭✭
    edited October 2017

    If to install Microsoft.Azure.Mobile.Client and System.Net.Http NuGet packages, and register with:

        public override void OnTokenRefresh()
        {
            var refreshedToken = FirebaseInstanceId.Instance.Token;
            Log.Debug(Tag, "Refreshed token: " + refreshedToken);
            SendRegistrationToServer(refreshedToken);
        }
    
        void SendRegistrationToServer(string token)
        {
            Task.Run(async () =>
            {
                MobileServiceClient client = new MobileServiceClient("http://my-mobile-app-url.azurewebsites.net");
                await AzureNotificationHubService.RegisterAsync(client.GetPush(), token);
            });
        }
    

    Then it is possible to receive notification send from Azure, but exception is thrown on receiving because message.GetNotification() is null

  • What I did at result. Registration code is:

        void SendRegistrationToServer(string token)
        {
            const string templateBody = "{\"data\":{\"message\":\"$(messageParam)\"}}";
            JObject templates = new JObject();
            templates["genericMessage"] = new JObject
            {
                {"body", templateBody}
            };
    
            Task.Run(async () =>
            {
                MobileServiceClient client = new MobileServiceClient("http://lalala.azurewebsites.net");
                await client.GetPush().RegisterAsync(token, templates);
            });
        }
    

    By the way only Microsoft.Azure.Mobile.Client package needed.

    And when I receive message here is what I do:

            string text = "";
    
            if (message.Data.ContainsKey("message"))
            {
                text = message?.Data["message"];
            }
            else
            {
                text = message?.GetNotification().Body;
            }
    
  • AliRaza.5445AliRaza.5445 PKMember ✭✭✭

    @programmerhammer , My OnTokenRefresh method is not called. Where to call it from in order to register device with FCM ?

  • programmerhammerprogrammerhammer BYMember ✭✭

    It is called automatically only on first application start. Application should be configured. google-services.json should be added and you must implement interface MyFirebaseIIDService : FirebaseInstanceIdService
    Try this link for configuration description

  • TvtTvt NLMember

    @programmerhammer you are saying

    MobileServiceClient client = new MobileServiceClient("azurewebsite");

    This indicates that you already wrote the back-end? How would you do this if you did not have the back-end already and only the notification hub? the access read string from azure of course does not work.

    For some reason I am not able to register my application to the notificationhub even though I would like to.

  • programmerhammerprogrammerhammer BYMember ✭✭

    @Tvt
    No, backend is not required. "azurewebsite" - this is url of configured Azure Mobile App with notification hub.

  • RaasMasoodRaasMasood USMember

    @programmerhammer can you please tell me to ho register with tags ?
    the register function only takes token and template. how to register with tags ?

Sign In or Register to comment.