【问题标题】:Headsup notification and badge is not displaying in some android devices?Headsup 通知和徽章未在某些 Android 设备中显示?
【发布时间】:2019-04-09 17:25:38
【问题描述】:

如何在 xamarin 形式的 android 中显示提示通知和徽章,我正在使用 firebase 推送通知。它在某些设备(如 Redmi 6 pro 等)中显示提示通知和徽章计数...,我已经尝试过这个链接来实现推送通知:-https://github.com/CrossGeeks/FirebasePushNotificationPlugin .而我的json有效载荷是这样的。

{
"to":"push-token",
"priority": "high",
"notification": {
        "title": "Test",
        "body": "Mary sent you a message!",
        "sound": "default",
        "icon": "youriconname"
                }
 }

当应用程序处于终止状态并且应用程序处于后台时,它在 iOS 中运行良好。并且在应用程序打开时没有得到。

如何做到这一点,请帮帮我...

【问题讨论】:

    标签: c# xamarin.forms xamarin.android xamarin.ios


    【解决方案1】:

    我猜原因是您的 Activity 中没有定义通知渠道。

    MainActivity.cs你可以在onCreate方法中调用这个方法:

    void CreateNotificationChannel()
        {
            if (Build.VERSION.SdkInt < BuildVersionCodes.O)
            {
                // Notification channels are new in API 26 (and not a part of the
                // support library). There is no need to create a notification 
                // channel on older versions of Android.
                return;
            }
    
            var channel = new NotificationChannel(CHANNEL_ID, "FCM Notifications", NotificationImportance.Default)
                          {
                              Description = "**Description**"
                          };
    
            var notificationManager = (NotificationManager) GetSystemService(NotificationService);
            notificationManager.CreateNotificationChannel(channel);
        }
    

    在哪里

        internal static readonly string CHANNEL_ID = "my_notification_channel";
        internal static readonly int NOTIFICATION_ID = 100; 
    

    分别是频道ID和通知ID的定义。

    在加载 XF 后在 MainActivity 的 OnCreate 中调用:

    LoadApplication(new App());
    CreateNotificationChannel();
    

    祝你好运

    在查询的情况下恢复

    【讨论】:

    • 我添加了上面的代码。当应用程序打开时它不会显示任何提示消息。当应用程序处于终止状态时也不会收到通知。当应用程序在后台时它工作正常
    • 你可能想发布一个错误,因为这看起来更像是一个插件问题!
    • 实际上,这是我的错误,现在提示通知在vivo中工作正常,但是在redmi中,我的频道禁用了浮动通知,并且在默认频道中启用了它,如何启用这个我我的频道,我试过这个链接:-stackoverflow.com/questions/33172390/…,但它不起作用
    猜你喜欢
    • 1970-01-01
    • 2021-10-25
    • 1970-01-01
    • 2019-10-29
    • 2018-11-25
    • 2020-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多