我正在按照本教程来接收FCM背景通知https://docs.microsoft.com/en-us/xamarin/android/data-cloud/google-messaging/remote-notifications-with-fcm?tabs=macos。
但是我收到以下错误
[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与示例中引入的UI完全不同。 Microsoft应该更新该教程,但令我沮丧的是,我发现该教程已过时,并且在我尽一切所能时该教程不起作用。
答案 0 :(得分: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的定义。