skip to Main Content

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


  1. You need to consider the following scenarios when managing the notification:

    • Status of the application when the push notification reaches the device (foreground, background, or closed).
    • The type of operating system, that is, on iOS or Android.
    • The types of payloads that make up the message sent by the message server.

    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):

    {
       "notification":{
          "title":"title",
          "body":"text"
       },
       "data":{
          "title":"title",
          "body":"text",
          "score":"4.5"
       },
       "android":{
          "notification":{
             "priority":"high",
             "sound":"default",
             "clickAction":".PushReceiverActivity"
          }
       }
    }
    
    Login or Signup to reply.
  2. 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 .🙂

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search