Not long ago I started to learn FCM, I checked the tutorial on YouTube
https://www.youtube.com/watch?v=7w2q2D6mR7g
(there is an GitHub link in the description). This android app and notifications works perfect only when app is open or in foreground mode. When I killing my app, notifications not works.
I need to get notifications when my app is closed. For example: telegram notifications(It works always).
I tried to set an autostart mode in settings of my app, but can I do it without autostart?
I think the notification is not arrive because I send it by token, which refreshing every app restart:
public App() { InitializeComponent(); MainPage = new MainPage(); CrossFirebasePushNotification.Current.Subscribe("all"); CrossFirebasePushNotification.Current.OnTokenRefresh += Current_OnTokenRefresh; } private void Current_OnTokenRefresh(object source, FirebasePushNotificationTokenEventArgs e) { System.Diagnostics.Debug.WriteLine($"Token: {e.Token}"); }
2
Answers
You need to consider the following scenarios when managing the notification:
In the following article you can see a flow chart that the notifications follow: https://yaircarreno.medium.com/do-you-know-the-push-notification-flow-7eb67c7fa3f7
Example of message with notification and data payload (specifying activity that receives the notification):
Hey all folks here by spending over a day I have found a solution , FCM override function OnMessageRecieved will not call when app is killed , so you have to override Onhandleintent function inside your FCM . And from there you can add logic inside that function to show custom notification on the screen .🙂