Azure Notification Hubs Android Client SDK - FCM V1 Upgrade

Simone 0 Reputation points
2024-04-05T16:57:47.8433333+00:00

Been using this library and functions successfully since 2021 (haven't needed 1.1.6 update)

com.microsoft.azure:notification-hubs-android-sdk-fcm:1.1.4

registerTemplate works fine creating GcmTemplateRegistrationDescription and GcmRegistrationId in ANH

Now need to create the FcmV1TemplateRegistration and FcmV1RegistrationId so tried updating to 2.0.0

com.microsoft.azure:notification-hubs-android-sdk-fcm:2.0.0

Q: Does/Will this SDK have a function to create FcmV1TemplateRegistration registrations..?

Azure Notification Hubs
Azure Notification Hubs
An Azure service that is used to send push notifications to all major platforms from the cloud or on-premises environments.
282 questions
{count} votes

2 answers

Sort by: Most helpful
  1. SnehaAgrawal-MSFT 19,511 Reputation points
    2024-04-14T03:07:50.25+00:00

    @Simone Yes, our 2.0.0 SDK supports registerTemplate with FCMv1.

    You may refer the documentation about migration: Azure Notification Hubs and the Google Firebase Cloud Messaging (FCM) migration using SDKs | Microsoft Learn

    Please note that the payload for FCMv1 is different and you will need to update your templates: Migrate from legacy FCM APIs to HTTP v1  |  Firebase Cloud Messaging (google.com)


  2. Simone 0 Reputation points
    2024-06-17T06:34:29.27+00:00

    Re-submitting this question because we've made quite a bit of progress, but not quite sorted yet. Been using this library and functions successfully since 2021 in my Android App

    com.microsoft.azure:notification-hubs-android-sdk-fcm:1.1.4

    registerTemplate creates GcmTemplateRegistrationDescription and GcmRegistrationId fine

    Need to create FcmV1TemplateRegistration and FcmV1RegistrationId so updated to 2.0.0

    com.microsoft.azure:notification-hubs-android-sdk:2.0.0

    Call to registerTemplate on device now creates FcmV1TemplateRegistration in Azure Hub

    (Get Android device regid with FirebaseMessaging.getInstance().getToken() function first)

       String messageTemplate = "{\"message\":{\"android\":{\"data\":{\"msgtext\":\"$(msgtext)\",\"msgsndr\":\"$(msgsndr)\"}}}}";
    
       String RegistrationTagTopic = "5050";
    
       mobile_RegistrationId = hub.registerTemplate(regid, "CAREV1", messageTemplate, RegistrationTagTopic).getRegistrationId();
    

    Example registration: mobile_RegistrationId returned above is Notification Hub RegistrationId

    
    <ETag>5</ETag>
    
    <ExpirationTime>2124-06-12T05:55:24.1941413Z</ExpirationTime>
    
    <RegistrationId>2837404...516-2</RegistrationId>
    
    <Tags>5050</Tags>
    
    <FcmV1RegistrationId>eZMPxd2pQBi...Uh</FcmV1RegistrationId>
    
    <BodyTemplate><![CDATA[{"message":{"android":{"data":{"msgtext":"$(msgtext)","msgsndr":"$(msgsndr)"}}}}]]></BodyTemplate>
    
    <TemplateName>CAREV1</TemplateName>
    
    </FcmV1TemplateRegistrationDescription>
    
    

    It seems the format of the template in the App for FCMv1 is absolutely critical because my App threw an exception on register with any other format than {"message":{"android":{"data":{...}}}}

    Send to device tag 5050 using Azure Notification Hubs REST API Method, same API call we've used successfully since 2015 (presume you know how to generate your Authorization token): Send a template notification with parameters like;

       ServiceBusNotification-Format = "template"
    
       ServiceBusNotification-Tags = "5050"
    
       ContentType = "application/json;charset=utf-8."
    
       Method = "POST"
    
       URI = "https://{namespace}.servicebus.windows.net/{NotificationHub}/messages/?api-version=2015-01"
    

    Example of JSON posted in the call

    {"message":{"android":{"data":{"msgtext":"My short message","msgsndr":"ADMIN"}}}}
    

    Notification is received on the device fine, but there is no payload

    Logged using &test mode with REST API, everything looks like it worked, Reg Id and PnsHandle both match and recognizes fcmV1Template

    
    address    : 5050
    
    Success : 1
    
    Failure : 0
    
    Appform : fcmV1Template
    
    Reg  Id : 2837404...516-2
    
    PnsHandle : eZMPxd2pQBi...Uh
    
    Outcome : The Notification was successfully sent to the Push Notification System
    
    

    Send (POST) same message direct to 5050 via FCM/JWT routine, slightly different JSON format;

    {"message":{"topic":"5050","data":{"msgtext":"My short message","msgsndr":"ADMIN"},"android":{"priority":"high"},"fcm_options":{"analytics_label":"xyz"}}}
    

    Notification and message payload are perfect (note extra FCM parameters) and works every time. Of course, FCM doesn't require a template in the App itself or the server process.

    Question: What's going wrong with my template send via Notification Hubs..?

    0 comments No comments