Issue
I'm trying to change the content of a push notification received from firebase. This is the application class in the Android project:
public class MainApplication : Application
{
public MainApplication(IntPtr handle, JniHandleOwnership transer) : base(handle, transer)
{
}
public override void OnCreate()
{
base.OnCreate();
//Set the default notification channel for your app when running Android Oreo
if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
{
//Change for your default notification channel id here
FirebasePushNotificationManager.DefaultNotificationChannelId = "FirebasePushNotificationChannel";
//Change for your default notification channel name here
FirebasePushNotificationManager.DefaultNotificationChannelName = "General";
FirebasePushNotificationManager.DefaultNotificationChannelImportance = NotificationImportance.Max;
}
//If debug you should reset the token each time.
#if DEBUG
FirebasePushNotificationManager.Initialize(this, true);
#else
FirebasePushNotificationManager.Initialize(this, false);
#endif
FirebasePushNotificationManager.IconResource = Resource.Drawable.logogiusto;
FirebasePushNotificationManager.Color = Android.Graphics.Color.Red;
//Handle notification when app is closed here
CrossFirebasePushNotification.Current.OnNotificationReceived += (s, p) =>
{
//var hardware_token=Xamarin.Essentials.SecureStorage.GetAsync("hardware_token");
//Interface inter = new Interface();
//float share=inter.GetShareOnHardwareToken(hardware_token);
FirebasePushNotificationManager.NotificationContentTitleKey = "foobar";
System.Diagnostics.Debug.WriteLine(FirebasePushNotificationManager.NotificationContentTitleKey);
};
}
Basically, I need to change the notification content with some data that I can get only via the user app (until the session is expired)*. I thought about dealing with it using tokens instead of topics but since the app requires sending notifications to users at the same moment, it might become bulky on my side.
I also tried using
FirebasePushNotificationManager.NotificationContentTitleKey = "foobar";
as you can see from the code above, but it simply does nothing and the content still is the one I choose on firebase.
One interesting aspect is that I get this on the debug window whenever I receive a push notification from firebase:
[FirebaseMessaging] Unable to log event: analytics library is missing
[FirebaseMessaging] Missing Default Notification Channel metadata in AndroidManifest. Default value will be used.
Although I cannot fully understand what is this referring to.
*If what I receive from firebase is NEW NOTIFICATION FROM FIREBASE it needs to become NEW NOTIFICATION FROM ABC
Solution
Set the meta name correctly so the Default Notification Channel can be recognized like:
<meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="@string/notification_channel_id" />
Answered By - Adrain Zhu -MSFT
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.