0

I have an Android application with Xamarin and I use FirebaseMessaging to receive notifications. I receive notifications when the app is closed, and I receive notifications in app, when the app is open.

When my app is running in DEBUG mode, everything is working, I get notifications fine.

But, when my app is running in RELEASE mode, or if I use the APK of my application, the notifications IN APP only no longer work... But they still work if the app is closed.

Here the code to *get the token *:

     public string GetToken()
        {
            string token = CrossFirebasePushNotification.Current.Token;
          
            return token;
        }

Here the code *to receive notifications when the app is running : *

[Service(Exported = false)]
    [IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
    public class FirebaseService : FirebaseMessagingService
    {

        public override void OnMessageReceived(RemoteMessage message)
        {
            //Log.Debug(TAG, "Venant de: " + message.From);
            //Log.Debug(TAG, "Contenu de la notif: " + message.GetNotification().Body);

            if (message.GetNotification() != null)
            {
                long longDate = message.SentTime;
                DateTime start = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                DateTime dateTimeNotif = start.AddMilliseconds(longDate).ToLocalTime();

                EventCatch newNotif = new EventCatch
                {
                    Id_Client = AccesData.clientCourant.Id_Client,
                    Id_Compte = AccesData.compteCourant.Id_Compte,
                    NotifTitle = message.GetNotification().Title,
                    NotifBody = message.GetNotification().Body,
                    Lu = false,
                    NotifDateHeureEnvoi = dateTimeNotif,
                };

                AccesData accesData = new AccesData();
                accesData.SauvEventLocal(newNotif);

                accesData.OnNewEvent(newNotif);
            }
        }
}

Here the code of the event to catch the body of the notification, when app IS RUNNING, and show it to the user :

  public void OnNewEvent(EventCatch eventCatch)
        {
            RecupNotif?.Invoke(eventCatch, EventArgs.Empty);
        }

And the delegate, in the code behind of my XAML Page:

 AccesData.RecupNotif += ShowNewNotification;

The *function *(when notification is received, I have a bell that turns red in the navigation bar) :

  private void ShowNewNotification(object sender, EventArgs e)
        {
            //frameNotif.IsVisible = true;
            btnAlertNotif.BackgroundColor = Color.Red;
        }

In the DEBUG MODE, everything is working, I receive all the notifications, in the application, and also when the app is closed.

But in RELEASE mode, only the IN-APP notification dont't work, with the APK, or in PRODUCTION...

I can't understand why ? I've been stuck on it for over a month.

it seems that this unanswered question is similar to my problem

Any ideas ? Thanks for help.

EDIT :

I have also :

  • generate my SHA-1 key
  • Add my SHA-1 to firebase console
  • download the new google-services.json
  • add I added it in my application

But the notifications IN-APP still don't work...

My certificates

Little_Dev
  • 107
  • 8

3 Answers3

1

I was finally able to find where all my problem came from.

I was actually using two packages to use the notifications in my application.

The first was Plugin.FirebasePushNotification, with which I generated my token and initialized the service on app launch.

And the second was Xamarin.Firebase.Messaging, with which I was getting the notifications messages, but also initializing the service with it, in my MainActivity.

So I removed everything from Plugin.FirebasePushNotification in order to only use Xamarin.Firebase.Messaging.

And now it works wonderfully...

Thank you all!

Little_Dev
  • 107
  • 8
0

Does your google-services json contain an additional SHA certificate fingerprint for your release build?

user2153142
  • 431
  • 1
  • 4
  • 7
  • I don't need no additional SHA certificate fingerprint ? The application is already signed by google certificate and validated by the PlayStore. – Little_Dev Mar 06 '23 at 08:36
0

You can first recheck if you have added your SHA-1 key of signature for the release to your firebase console.

For released version, there is a different SHA-1 key .

You can try the following steps:

  • Generate your SHA-1 for release
  • Add your release SHA-1 to firebase console
  • Download and use new google-services.json.

Note: Make sure the key being used by play store to sign your releases is also added in step 2

There are some similar threads about this problem,you can check them here:

FCM notifications not working in release app

Firebase google authentication not working in release mode

Jessie Zhang -MSFT
  • 9,830
  • 1
  • 7
  • 19
  • thx for your answer. I did what you said, but I still don't get notifcations in-app. I edited my question with the new information. Do you have any other ideas of what i might be missing? ? – Little_Dev Mar 07 '23 at 09:22
  • Have you used `proguard` or set `Linker` to `SDK Assemblies Only` or `Sdk and User Assemblies` in release mode? – Jessie Zhang -MSFT Mar 08 '23 at 05:28