I get messages in the background but don’t show the badge with the message counter

Asked

Viewed 79 times

1

In my App I can receive messages in Background. In foreground I can see the badge and qde of incoming messages. I just can’t in the background. I use the plugin Xamarin.Firebasepushnotification of Rendydelrosario, which I liked enough to receive PN. Talking to Rendy via skype yesterday, he told me this:

You cannot use Xamarin Forms code when application is closed so that won’t work Xamarin Forms Features need the application to be opened in order to work because is initialized. But when closed Xamarin Forms is not initialized because initialization depends on UI You need to update this without the use of any Xamarin Forms dependencies in order for it to work

Well, I altered the event receiving the App.xmal.Cs for Mainapplication.Cs, as below and yet I still keep getting PN and not showing the badge: Mainapplication

public override void OnCreate()
        {
                base.OnCreate();

                //If debug you should reset the token each time.
#if DEBUG
                FirebasePushNotificationManager.Initialize(this, true);
#else
                FirebasePushNotificationManager.Initialize(this, false);
#endif
            try
            {
                //Handle notification when app is closed here
                CrossFirebasePushNotification.Current.OnNotificationReceived += (s, p) =>
                {
                    System.Diagnostics.Debug.WriteLine("Received");
                    Xamarin.Forms.MessagingCenter.Send<Autorizador.Droid.MainApplication>(this, "PushNotificationRecievedClosed");
                };
            }
            catch(Exception ex)
            {
                string err = ex.Message;
            }
        }

Mainactivity

protected override void OnCreate(Bundle bundle)
        {
            try
            {
                instance = this;
                TabLayoutResource = Resource.Layout.Tabbar;
                ToolbarResource = Resource.Layout.Toolbar;

                base.OnCreate(bundle);

                global::Xamarin.Forms.Forms.Init(this, bundle);

                badge = new Badge(this);

                MessagingCenter.Subscribe<App>(this, "PushNotificationRecieved", (sender) => {
                    Contador++;
                    badge.count(Contador);
                });

                MessagingCenter.Subscribe<Autorizador.Droid.MainApplication>(this, "PushNotificationRecievedClosed", (sender) => {
                    Contador++;
                    badge.count(Contador);
                });

                MessagingCenter.Subscribe<App>(this, "ResetBadge", (sender) => {
                    Contador = 0;
                    badge.count(Contador);
                });                

                LoadApplication(new App());

                FirebasePushNotificationManager.ProcessIntent(Intent);

            }
            catch(Exception ex)
            {
                string err = ex.Message;
            }
        }

Can anyone tell me why I can’t show the badge when the app is in background?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.