首页 > 解决方案 > Xamarin Android 无法接收举手通知(横幅通知)

问题描述

我正在我的应用程序上构建通知系统,但问题出在 Andorid Os 中,尤其是华为 p20 lite 我无法在屏幕顶部获得通知横幅

我尝试了很多教程

( https://snag.gy/xy2ImQ.jpg ) 图片 我希望这是真的或激活

Xamarin:

    {
        var intent = new Intent(this, typeof(MainActivity));
        intent.AddFlags(ActivityFlags.ClearTop);
        intent.PutExtra("SomeSpecialKey", "some special value");
        foreach (var key in data.Keys)
        {
            intent.PutExtra(key, data[key]);
        }

        var pendingIntent = PendingIntent.GetActivity(this,
                                                      MainActivity.NOTIFICATION_ID,
                                                      intent,
                                                      PendingIntentFlags.OneShot);

        var notificationBuilder = new  NotificationCompat.Builder(this, MainActivity.CHANNEL_ID)
                                  .SetSmallIcon(Resource.Drawable.ic_stat_ic_notification)
                                  .SetContentTitle(title)
                                  .SetContentText(messageBody)
                                  .SetPriority(5)
                                  .SetDefaults(1)
                                  .SetVibrate(new long[0])

                                  .SetContentIntent(pendingIntent);





       /*   NotificationChannel channel = new NotificationChannel(
                                MainActivity.CHANNEL_ID,
                               new Java.Lang.String("Channel"),
                                NotificationImportance.High
                            ); */

        var notificationManager = NotificationManagerCompat.From(this);
        notificationManager.Notify(MainActivity.NOTIFICATION_ID, notificationBuilder.Build());

    }

本地服务器:

{"to":"MYTOKEN","notification":{"title":"Working Good","body":"Okok" ,"sound": "default",
      "icon": "icon_desc"},"priority":"high",
}

标签: c#androidfirebasexamarinpush-notification

解决方案


我发现我的解决方案我创建了自定义频道

internal static readonly string CHANNEL_ID = "test";

我确实直接从 JSON Payload 文件设置了属性

{
   "to": "fOBdGjbftTI:APA91bEV1G39J3sF-CBQMANdlW7ely-XGC8zQ9Fp00H31iHFsmxB5hcgFCMr8-Plh9w4bDHO9eDQ5Fr_SCbYjNJ93iaFvh-zcUe_e1sAKHmRo5u73vGMuGovmfvUuTIuak1xcoRTrOtQ",
   "notification":{
     "title":"New Notification!",
     "body":"Test",
"android_channel_id":"test"
   }, 
   "priority":"High",

    "android": {
            "notification": {
                "sound": "default"
            }
        } 
}

推荐阅读