Issues with push notifications using Azure Notification Hubs.

Jacob Vermeule 10 Reputation points
2025-03-10T11:40:45.8833333+00:00

I am trying to send push notifications to my Android app using Azure Notification Hubs, but despite getting a 201 HTTP status code when sending a request, I am not receiving the push notification to my device. When sending notifications via Firebase Cloud Messaging directly, everything works as expected, and notifications are delivered to the device. I can also see my device being registered in Notification Hubs.

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.
353 questions
{count} vote

2 answers

Sort by: Most helpful
  1. Erik 0 Reputation points
    2025-03-11T07:00:47.7666667+00:00

    Hi Gaurav Kumar,

    Thanks for your suggestions. One quick question, when you mention the FCM API key, are you referring to the legacy FCM API? As far as I know, FCM now requires using service account credentials (JSON key) for authentication instead of the old API key.

    We tracked a message sent via Azure Notification Hubs using the Telemetry API and saw the error "NoTargets", meaning there were no registered devices to send to.

    However, when we check the Azure Notification Hubs Overview, the device appears to be registered. Also when we run a GET API call to retrieve registrations, we see the device listed with its FCM token.


  2. Gaurav Kumar 0 Reputation points Microsoft External Staff
    2025-03-12T09:24:37.56+00:00

    Hi @Anonymous ,

    Firstly, addressing Erik’s findings regarding authentication. FCM has moved away from the legacy API key, and Azure Notification Hubs now requires using a service account JSON key for authentication instead. If you’re still using the old API key, ANH might appear to accept the request, but the notifications won’t actually be sent. Please check your Azure Notification Hub settings under Firebase (FCM) Configuration and make sure the correct OAuth 2.0 JSON key is uploaded.

    One possible cause is that the FCM token stored in ANH may not be up-to-date. FCM tokens can change over time, and if ANH has an old token, it won’t be able to deliver the notification. You can check the current token in the app logs by running:

    FirebaseMessaging.getInstance().getToken()
       .addOnCompleteListener(task -> {
           if (!task.isSuccessful()) {
               Log.w("FCM", "Fetching FCM token failed", task.getException());
               return;
           }
           Log.d("FCM", "FCM Token: " + task.getResult());
       });
    

    Then, compare it with the one registered in ANH using this command:

    az notification-hub registration list --resource-group <resource-group> \  
    --namespace-name <namespace> --notification-hub-name <notification-hub>
    

    If the tokens don’t match, the best approach is to re-register the device with the latest token.

    Another thing to check is whether the notification is being sent to the correct target type. If you’re using direct device targeting, the payload should look like this:

    {  
    	"to": "<FCM-TOKEN>"  
    }  
    

    If you’re using tag-based targeting, Check the device registration includes the correct tag(s) and that the notification is being sent to those tags.

    Additionally, Android’s Doze Mode and battery optimizations could be preventing notifications from being delivered, especially if the priority is set to normal. Try setting the priority to high in your payload:

    {   "notification": {     "title": "Test Notification",     "body": "Hello from Azure Notification Hubs!"   },   "android": {     "priority": "high"   } }
    

    Hope it helps!


    Please do not forget to click "Accept the answer” and Yes wherever the information provided helps you, this can be beneficial to other community members.

    User's image

    If you have any other questions or still running into more issues, let me know in the "comments" and I would be happy to help you.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.