首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用FirebaseNotificationPushManger更改通知文本

使用FirebaseNotificationPushManger更改通知文本
EN

Stack Overflow用户
提问于 2021-12-30 01:25:30
回答 1查看 270关注 0票数 0

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

代码语言:javascript
运行
复制
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);

            };
        }

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

我还试着用

代码语言:javascript
运行
复制
FirebasePushNotificationManager.NotificationContentTitleKey = "foobar";

正如您从上面的代码中可以看到的那样,但是它什么也不做,而且内容仍然是我在firebase上选择的内容。

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

代码语言:javascript
运行
复制
[FirebaseMessaging] Unable to log event: analytics library is missing
[FirebaseMessaging] Missing Default Notification Channel metadata in AndroidManifest. Default value will be used.

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

*如果我从消防基地收到的是来自火车头的新通知,它需要成为ABC的新通知。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-01-04 02:32:28

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

代码语言:javascript
运行
复制
 <meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="@string/notification_channel_id" />
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70526592

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档