Closed Mano176 closed 3 weeks ago
I now managed to send notifications via an own .net project:
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", "[path to]\\firebase-adminsdk.json");
FirebaseApp.Create(new AppOptions()
{
Credential = GoogleCredential.GetApplicationDefault(),
});
string registrationToken = "my device token";
// See documentation on defining a message payload.
Message message = new Message()
{
Token = registrationToken,
//Data = new Dictionary<string, string>()
//{
// { "title", "Weather Update" },
// { "body", "Pleasant with clouds and sun" },
//},
Notification = new Notification()
{
Title = "Title",
Body = "I am a message sent via the .NET Project",
},
Android = new AndroidConfig()
{
Priority = Priority.High,
},
};
string response = FirebaseMessaging.DefaultInstance.SendAsync(message).GetAwaiter().GetResult();
Console.WriteLine("Successfully sent message: " + response);
I'm not quite sure wether I should use the Notification
or Data
parameter there. But with both approaches I get the same results as described above.
I am also confused wether we should include any receiver tags in the AndroidManifest.xml like this guy did: #17 So far doing this does not seem to change anything for me.
I should maybe also mention, that receiving background notifications only seems to work really unreliable and there's a huge delay between sending and receiving them (foreground notifications are received instantly).
I updated the nuget reference from 1.0.26 to 2.2.69-pre and now everything seems to work fine. Had to do some migrations. Most of them were renaming events, one bigger migration was adding this to CreateMauiApp:
.UseFirebasePushNotifications(options: (FirebasePushNotificationOptions options) =>
{
options.Android.NotificationChannels =
[
new NotificationChannelRequest()
{
ChannelId = "LMDefaultNotificationChannel",
ChannelName = "My Channel Name",
Description = "Channel Description",
Importance = Android.App.NotificationImportance.Max,
IsDefault = true
}
];
})
The stuff in OnNotificationReceived
is no longer needed and NotificationOpened
is not called properly when I click the notifications. Also my OnCreate method now properly receives the notification data.
One small thing I noticed (that might help others) is, that when I debug the app with Visual Studio and then close the app, I have to open the app once again (but this time from the device and not with Visual Studio) and close it again to be able to receive background notifications.
First of all, I‘m sorry that version 1.x is still the latest stable version. 1.x was the direct migration from the previous xamarin plugin for FCM.
To the other points, I‘ll come back to you as soon as I can. The steps you went trough and the comments noted help me to understand where I have to extend to documentation. (I know, it barely doesnt exist…).
@Mano176 you can try the latest version of the plugin. It‘s now more stable and tested with a lot of different push notification messages.
If there is still anything unclear or buggy, I kindly ask you to open a new issue - or we reopen this one 👍🏻
Hello, I am trying to receive notifications on Android but I am facing two problems which I am unable to solve by looking at the examples in the sample project and in the readme and the other issues.
Problem 1
Foreground notifications (notifications the app receives while the it is running) only call OnNotificationReceived but don't show the notification in the status bar. I tried to trigger a local notification in OnNotificationReceived but I have the feeling that this is not the intended way.
Problem 2
Background notifications (notifications the app receives while it is not running) are displayed in the status bar like the first image in your readme and clicking on them opens the app. I also see that in OnCreate the Intent.Extras bundle is not empty, but it does not contain my notification data (title, body and additional data). The bundle just contains the follwing data:
My code in MainActivity.cs
I am creating the notifications via https://console.firebase.google.com/project/[myproject]/notification/compose
I have the feeling that I am just missing some fundamental part in the setup, but am lost to what exactly is wrong. I hope you can help me out here.