使用FirebaseNotificationPushManger更改通知文本



我正在尝试更改从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的新通知

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

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

最新更新