无法通过Microsoft官方示例接收FCM后台通知

问题描述 投票:1回答:1

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

我使用Firebase中的“Test on device”发送消息:enter image description here

但是我收到以下错误

[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个回答
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>

请检查这是否有效,如果没有还原,还要确保接收器位于<application>标签内,而不是<manifest>标签。

更新:

另外,检查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的定义。

© www.soinside.com 2019 - 2024. All rights reserved.