使用 FirebaseNotificationPushManger 更改通知文本

Changing notification text using FirebaseNotificationPushManger

我正在尝试更改从 firebase 收到的推送通知的内容。 这是 Android 项目中的应用程序 class:

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);

            };
        }

基本上,我需要用一些只能通过用户应用程序获取的数据更改通知内容(直到会话过期)*。 我考虑过使用令牌而不是主题来处理它,但由于该应用程序需要同时向用户发送通知,所以我这边可能会变得笨重。

我也试过使用

FirebasePushNotificationManager.NotificationContentTitleKey = "foobar";

正如您从上面的代码中看到的,但它什么也没做,内容仍然是我在 firebase 上选择的内容。

一个有趣的方面是,每当我收到来自 firebase 的推送通知时,我都会在调试 window 上得到这个:

[FirebaseMessaging] Unable to log event: analytics library is missing
[FirebaseMessaging] Missing Default Notification Channel metadata in AndroidManifest. Default value will be used.

虽然我不能完全理解这是指什么。

*如果我从 firebase 收到的是 NEW NOTIFICATION FROM FIREBASE 它需要变成 NEW NOTIFICATION FROM ABC

正确设置元名称以便默认通知通道可以像这样被识别:

 <meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="@string/notification_channel_id" />