【问题标题】:Changing notification text using FirebaseNotificationPushManger使用 FirebaseNotificationPushManger 更改通知文本
【发布时间】:2021-12-30 01:25:30
【问题描述】:

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

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 的推送通知时,我都会在调试窗口中看到这个:

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

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

*如果我从 firebase 收到的是来自 FIREBASE 的新通知,它需要变成 来自 ABC 的新通知

【问题讨论】:

  • 您可能没有正确设置元名称。将其设置为
  • 是的,这似乎解决了问题。虽然我的 Android 项目中没有 strings.xml 文件,但我需要创建它。

标签: c# firebase xamarin firebase-cloud-messaging firebase-notifications


【解决方案1】:

正确设置元名称,以便可以识别默认通知通道:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-07
    • 2015-06-03
    • 1970-01-01
    • 1970-01-01
    • 2020-12-30
    相关资源
    最近更新 更多