在 Android 12 上未收到 Firebase 推送通知

Bla*_*kie 7 android pixel xamarin google-cloud-firestore android-12

我的 Xamarin.Android 应用程序的推送通知仅适用于 Android 11 (Pixel 3 XL)。目前,我的应用程序针对的是 Android 11,但它也可以在 Android 12 (Pixel 6 Pro) 上运行。唯一不起作用的是 Firebase 推送通知。下面是我正在使用的代码。在过去的一周里,我一直在研究这个问题,并看到了有关 Android 12 (Pixel 6) 未收到推送通知的特定问题的帖子。我按照其他人的建议对手机配置进行了更改,另一个应用程序通知开始工作,但我的仍然没有。任何想法都会有所帮助。谢谢。

 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.


                var name = "NameOfChannel";
                var description = "Notification Channel";
                var channel = new NotificationChannel(CHANNEL_ID, name, NotificationImportance.Max)
                {
                    Description = description
                };

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

            }       
Run Code Online (Sandbox Code Playgroud)

bas*_*ure 5

我错过的是

PendingIntent.FLAG_IMMUTABLE
Run Code Online (Sandbox Code Playgroud)

如果通知有pendingIntent,则为其设置可变/不可变标志


Bla*_*kie 3

找到了解决方案。也就是在 AndroidManifest.xml 中的 Firebase 服务标记上添加android:exported="false"

  • 我已经将导出=“假”添加到FirebaseMessageService服务,但仍然没有收到任何通知。 (3认同)