I am using this for my Xamarin.Forms application but its not handeling the CrossFirebasePushNotification.Current.OnNotificationReceived method in the Android project. I can receive a notification if the application is killed but its not handeling the method. What do I wrong?
[Application]
public class MainApplication : Application
{
int badgeCount = 0;
public MainApplication(IntPtr handle, JniHandleOwnership transer) : base(handle, transer)
{
}
public override void OnCreate()
{
base.OnCreate();
try
{
FirebasePushNotificationManager.Initialize(this, new NotificationUserCategory[]
{
new NotificationUserCategory("message",new List<NotificationUserAction> {
new NotificationUserAction("Reply","Reply",NotificationActionType.Foreground),
new NotificationUserAction("Forward","Forward",NotificationActionType.Foreground)
}),
new NotificationUserCategory("request",new List<NotificationUserAction> {
new NotificationUserAction("Accept","Accept",NotificationActionType.Default,"check"),
new NotificationUserAction("Reject","Reject",NotificationActionType.Default,"cancel")
})
}, false);
CrossFirebasePushNotification.Current.OnTokenRefresh += (s, p) =>
{
App.token = p.Token;
Console.WriteLine(p.Token);
};
CrossFirebasePushNotification.Current.Subscribe("news");
App.token = CrossFirebasePushNotification.Current.Token;
ME.Leolin.Shortcutbadger.ShortcutBadger.ApplyCount(this, 0);
//Handle notification when app is closed here
CrossFirebasePushNotification.Current.OnNotificationReceived += (s, p) =>
{
badgeCount++;
ME.Leolin.Shortcutbadger.ShortcutBadger.ApplyCount(this, badgeCount);
var message = p.Data;
var test = s;
try
{
Task.Run(() => ViewModelLocator.MainChatViewModel.InitializeChatAsync()).Wait();
}
catch (Exception) { }
};
CrossFirebasePushNotification.Current.OnNotificationOpened += (s, p) =>
{
badgeCount = 0;
ME.Leolin.Shortcutbadger.ShortcutBadger.ApplyCount(this, badgeCount);
try
{
Task.Run(() => ViewModelLocator.MainChatViewModel.InitializeChatAsync()).Wait();
}
catch (Exception) { }
};
}
catch (Exception)
{
}
}
}