【问题标题】:Could not receive FCM background notification via following an official Microsoft sample无法通过遵循官方 Microsoft 示例接收 FCM 后台通知
【发布时间】:2019-05-31 22:19:04
【问题描述】:

我正在按照本教程接收 FCM 后台通知https://docs.microsoft.com/en-us/xamarin/android/data-cloud/google-messaging/remote-notifications-with-fcm?tabs=macos。

我使用 Firebase 的“设备测试”来发送消息:

但我收到以下错误

[FirebaseMessaging] Unable to log event: analytics library is missing [FirebaseMessaging] Missing Default Notification Channel metadata in AndroidManifest. Default value will be used. [FirebaseMessaging] Error while setting the notification channel [FirebaseMessaging] java.lang.NoSuchFieldError: No static field fcm_fallback_notification_channel_label of type I in class Lcom/google/android/gms/R$string; or its superclasses (declaration of 'com.google.android.gms.R$string' appears in /data/app/com.xamarin.fcmexample-sq_amXpUDW9K_irSBnrndA==/base.apk) [FirebaseMessaging] at com.google.firebase.messaging.zza.zzrj(Unknown Source:195) [FirebaseMessaging] at com.google.firebase.messaging.zza.zzs(Unknown Source:273) [FirebaseMessaging] at com.google.firebase.messaging.FirebaseMessagingService.handleIntent(Unknown Source:189) [FirebaseMessaging] at com.google.firebase.iid.zzg.run(Unknown Source:26) [FirebaseMessaging] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) [FirebaseMessaging] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) [FirebaseMessaging] at java.lang.Thread.run(Thread.java:764)

有人知道怎么解决吗?或者有人知道让 Xamarin Android 应用接收 FCM 后台通知的可行教程吗?

顺便说一句:在我看来,该教程有点过时了,因为 Firebase 控制台 UI 与示例中介绍的完全不同。微软应该更新教程,我​​很沮丧地发现一个教程已经过时了,当我尽我所能的时候它没有工作。

【问题讨论】:

    标签: firebase xamarin xamarin.android firebase-cloud-messaging


    【解决方案1】:

    我感觉接收器丢失了请检查您是否在清单文件中添加了以下内容:

      <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" />
        <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                <category android:name="${applicationId}" />
            </intent-filter>
        </receiver>
    

    请检查这是否有效,如果不能恢复,请确保接收器位于&lt;application&gt; 标签内,而不是&lt;manifest&gt; 标签内。

    更新:

    另外,检查 MainActivity 中是否需要通知通道。您可以在 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 = "Firebase Cloud Messages appear in this channel"
                          };
    
            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的定义。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-29
      • 1970-01-01
      • 2016-12-24
      • 1970-01-01
      • 2017-12-09
      • 2017-11-29
      • 2020-06-21
      • 2018-06-13
      相关资源
      最近更新 更多