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...