FirebasePushNotificationPlugin
FirebasePushNotificationPlugin copied to clipboard
OnNotificationOpened not hit when app killed on Android
🐛 Bug Report
The notification comes through even when app is killed, but when clicking on notification, it doesn't run OnNotificationOpened method (which is on MainApplication.cs) and the body is:
CrossFirebasePushNotification.Current.OnNotificationOpened += (s, p) =>
{
string tag = "aimmsapp";
Android.Util.Log.Info(tag, "Opened");
System.Diagnostics.Debug.WriteLine("Opened");
foreach (var data in p.Data)
{
System.Diagnostics.Debug.WriteLine($"{data.Key} : {data.Value}");
}
};
I can see from the device logs that this method is not ran, but when the device is in background, it runs when I click the notification.
The payload sent is:
var pushData = new
{
to = deviceToken,
content_available = true,
data = new
{
body = message,
payload = new
{
android = new
{
title = title,
alert = message,
sound = "default",
vibrate = true,
icon = "appicon"
},
},
extData = extData
},
priority = "high"
};
Expected behavior
It should ran OnNotificationOpened method on MainApplication when I click the notification.
Reproduction steps
Kill the app, and send notification. OnNotificationOpened method should not ran when clicking the notification.
Configuration
Bug on Poco X3 NFC and Samsung Galaxy tab A (2016) Version: 3.4.1
Platform:
- [ ] :iphone: iOS
- [X] :robot: Android
- [ ] :checkered_flag: WPF
- [ ] :earth_americas: UWP
- [ ] :apple: MacOS
- [ ] :tv: tvOS
- [X] :monkey: Xamarin.Forms
Hello, have you found a solution to this ?
No solution yet.
If you have a splash Activity which is set to MainLauncher = true, Update your Activity like below. `public class SplashActivity : Activity { protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); FirebasePushNotificationManager.ProcessIntent(this,Intent); } protected override void OnNewIntent(Intent intent) { base.OnNewIntent(intent); FirebasePushNotificationManager.ProcessIntent(this,intent); } protected override void OnResume() { base.OnResume(); Task startupWork = new Task(() => { SimulateStartup(); }); startupWork.Start(); }
async void SimulateStartup()
{
await Task.Delay(0000); // Simulate a bit of startup work.
StartActivity(new Intent(Application.Context, typeof(MainActivity)));
}
}`
Hello i solved this by moving the event set to the Application constructor instead of the OnStart()
method described in the sample
public App()
{
InitializeComponent();
MainPage = new Views.StartupPage();
CrossFirebasePushNotification.Current.OnNotificationReceived += async (s, p) =>
{
await Task.Run(() =>
{
FirebaseClient.Model.Notification Notification = JsonConvert.DeserializeObject<FirebaseClient.Model.Notification>(p.Data["Notification"].ToString());
NotificationsViewModel.Default.OnNewNotification(Notification);
});
};
}
it seems that the event is launched too early for the app to catch even though the enableDelayedResponse
parameter is set to true
LoadApplication(new App());
FirebasePushNotificationManager.ProcessIntent(this, Intent);
This solved my problem and when user click the notification the appropriate page will appear but only on version 3.3.10
updating to the latest version 3.4.1
broke it again