I get messages in the background but does not show the badge with the message counter

1

In my App I get messages in Background. In foreground I can see the badge and the amount of messages received. I just can not get in the background. I use the RendyDelRosario Xamarin.FirebasePushNotification plugin , which I really enjoyed getting PN. Talking to Rendy via skype yesterday, he told me this:

  

You can not use Xamarin Forms code when application is closed so that   will not work Xamarin Forms features need the application to be opened in   order to work because it 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've changed the App.xmal.cs incoming event to MainApplication.cs as below and I still keep getting PN and not displaying 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 someone tell me why I can not show the badge when the app is in the background?

    
asked by anonymous 03.11.2017 / 13:51

0 answers