簡體   English   中英

Xamarin Android 中的 Android 設備未收到通知

[英]Notification Not Received on Android Device in Xamarin Android

實際上,我嘗試通過控制台中的“測試設備”選項發送單個設備的通知。 它顯示已完成但設備未收到通知。 然后我嘗試了 postman 和 pushtry.com,他們都給出了結果“Firebase 推送通知發送成功”,即使沒有收到 android 設備(谷歌像素版本 9)。 請幫我解決這個問題。

您的 MainActivity 中可能沒有通知通道,您可以將其配置如下:

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 = "Firebase Cloud Messages appear in this channel"
                  };

    var notificationManager = (NotificationManager) GetSystemService(NotificationService);
    notificationManager.CreateNotificationChannel(channel);
}

然后從 MainActivity 的 OnCreate 方法中調用

最小化您的應用程序(例如轉到儀表板或鎖定手機)並發送 FCM 推送通知。 如果您在這種情況下能夠收到通知,則表示您的 FCM 配置正確。 您共享的代碼僅在您在后台應用時才有效。 如果您希望在應用程序處於后台時收到通知。 您必須實現繼承 FireBaseMessagingService 調用並覆蓋 OnMessageRecived 方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM