【问题标题】:Firebase Push notification not receiving on Android 12在 Android 12 上未收到 Firebase 推送通知
【发布时间】:2022-07-27 17:16:23
【问题描述】:

我的 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);

            }       

【问题讨论】:

  • 我不确定您遇到什么问题,您是否收到异常或通知未显示......
  • @FreakyAli 当我从 Firebase 控制台同时向 Pixel 3 和 Pixel 6 手机发送测试消息时,只有 Pixel 3 Android 11 收到了消息。 Pixel 6 Android 12 手机的日志中没有显示错误。我检查了我的代码和 FCM 令牌以确保它是正确的。依然没有。谢谢。
  • 您是否应用了断点并检查您是否收到了它?
  • 据我所知,Android 12 在网络上有一些特别之处。您可以在下面的链接中获得进一步的帮助。 github.com/xamarin/xamarin-android/issues

标签: android xamarin google-cloud-firestore pixel android-12


【解决方案1】:

我错过的是

PendingIntent.FLAG_IMMUTABLE

如果 Notification 有 pendingIntent 则设置 mutable/immutable Flag 给它

【讨论】:

    【解决方案2】:

    找到了解决办法。这是在 AndroidManifest 中的 Firebase 服务标签上添加 android:exported="false"

    【讨论】:

    • 什么是 Firebase 服务标签?我在我的 AndroidManifest 文件中没有看到类似的内容,并且我遇到了同样的问题,即 Android 12 设备没有收到推送通知
    • 我已将exported="false" 添加到FirebaseMessageService 服务,但仍未收到任何通知。
    • 改成false有什么作用?
    【解决方案3】:
                   PendingIntent pendingIntent;
                    if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.S)
                    {
                    pendingIntent=PendingIntent.getActivity(context,notificationId,notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT|PendingIntent.FLAG_MUTABLE);
                    }
                    else
                    {
                    pendingIntent=PendingIntent.getActivity(context,notificationId,notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT);
                    }
                    builder.setContentIntent(pendingIntent)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-08
      • 2020-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多