I am going thru Microsoft's documentation for sending a push notification. I have the notificationhub up and running, a basic android app. I can successful send a message via the portal to the app.
I am trying to send a message to the app via the code below but notification id is
always blank
Snippet of my code
namespace PushToApp
{
class Program
{
static async Task Main()
{
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("config.json", optional: false)
.Build();
var nhClient = NotificationHubClient.CreateClientFromConnectionString(config["PrimaryConnectionString"], config["HubName"], true);
var message = "This a test";
var fcmDeviceId = Guid.NewGuid().ToString();
var fcmInstallation = new Installation
{
InstallationId = "fake-fcm-install-id",
Platform = NotificationPlatform.Fcm,
PushChannel = fcmDeviceId,
PushChannelExpired = false,
Tags = new[] { "fcm" }
};
await nhClient.CreateOrUpdateInstallationAsync(fcmInstallation);
await SendNotificationAsync(nhClient, message);
}
private static async Task SendNotificationAsync(NotificationHubClient nhClient, string message)
{
var alert = "{\"aps\":{\"alert\":\"" + message + "\",\"sound\":\"default\"}}";
var outcomeFcm = await nhClient.SendFcmNativeNotificationAsync(alert);
Console.WriteLine("result: " + outcomeFcm.Results.Count());
Console.WriteLine("state: " + outcomeFcm.State);
Console.WriteLine("Tracking Id: " + outcomeFcm.TrackingId);
Console.WriteLine("notification Id: " + outcomeFcm.NotificationId);
}
} //class
} //namespace
`
Output:
Count: 3
result:1
state:DetailedStateAvailable
Tracking Id:a8b19b49-9857-401f-a1b1-af7dcb896e8b
notification Id: