-
Notifications
You must be signed in to change notification settings - Fork 130
Description
I'm using Google Firebase Cloud Messaging (FCM) v1 API to send notifications. I have configured my project with the following details:
Private Key Client Email Project ID
Response : { "message": "Error sending notification: The notification has no target applications. The notification format is gcm. Review the credentials specified in the notification hub description and the notification format.. TrackingId:5da2a253-53eb-4416-9655-80da98ea8a0b,TimeStamp:1/8/2025 8:01:16 AM +00:00" }
I am trying to send a notification to an Android device using the Firebase Cloud Messaging (FCM) v1 API. Despite configuring the private key, client email, and project ID correctly, I receive an error stating, "The notification has no target applications." I want to ensure that the notification reaches any Android device successfully. How can I resolve this issue and make sure the notification is sent to the intended devices?
Tag : firebase-cloud-messaging, azure-notificationhub
Code:
public AzureNotificationService()
{
_hubClient = NotificationHubClient.CreateClientFromConnectionString(NotificationHubConnectionString, NotificationHubName);
}
public async Task<string> SendNotificationsAsync(string title, string body, string deviceToken)
{
try
{
var message = new
{
message = new
{
token = deviceToken,
notification = new
{
title = title,
body = body
},
data = new
{
additionalData = "your-custom-data"
}
}
};
string jsonMessage = JsonConvert.SerializeObject(message);
// Send notification using Azure Notification Hub
var outcome = await _hubClient.SendFcmNativeNotificationAsync(jsonMessage);
// Check the outcome for success or failure
if (outcome.State == NotificationOutcomeState.Enqueued)
{
return "Notification sent successfully!";
}
else
{
return $"Notification failed: {outcome.State}";
}
}
catch (Exception ex)
{
return $"Error sending notification: {ex.Message}";
}
}