如何修复 Firebase 通知



我已经正确实现了 Fire 基地通知,某些设备未收到通知 vivo,在后台运行时对焦 如何解决这个问题

 public void getNotification(String icon,String title,String body){
      remoteViews = new RemoteViews(getPackageName(),R.layout.custom_notification_big);
      remoteView  = new RemoteViews(getPackageName(),R.layout.custom_notification_small);
      //Bitmap bitmap = SetImage(remote.getIcon()) ;
      Intent intent = new Intent(this, MainActivity.class);
      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
      PendingIntent pendingIntent = PendingIntent.getActivity(this, 1410, intent, PendingIntent.FLAG_ONE_SHOT);
      NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
      if(icon!=null && !icon.isEmpty()){
        remoteViews.setImageViewBitmap(R.id.image_pic,bitmap);
      }else{
      }
      if(title != null && !title.isEmpty()){
          remoteViews.setTextViewText(R.id.title,title);
      }
      if(body != null && !body.isEmpty()){
          remoteViews.setTextViewText(R.id.text,body);
      }
      NotificationCompat.Builder notificationBuilder1 = new NotificationCompat.Builder(getApplicationContext())
              .setStyle(new NotificationCompat.DecoratedCustomViewStyle())
              .setCustomContentView(remoteView)
              .setCustomBigContentView(remoteViews)
              .setContentTitle("Notification")
              .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
              .setContentIntent(pendingIntent)
              .setAutoCancel(true)
              .setPriority(Notification.PRIORITY_MAX)
              .setDefaults(Notification.DEFAULT_VIBRATE);
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
      {
          notificationBuilder1.setSmallIcon(R.mipmap.ic_launcher);
      } else
      {
          notificationBuilder1.setSmallIcon(R.mipmap.ic_launcher);
      }
      notificationManager.notify(100, notificationBuilder1.build());
  }

您需要为此添加频道

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            notificationManager.createNotificationChannel(
                NotificationChannel(
                    "YOUR_ID",
                    "YOUR_NAME",
                    NotificationManager.IMPORTANCE_HIGH
                )
            )
        }

未收到通知!

使 firebase 在以下情况下调用您的 onMessageReceived((

1( 前台应用2(后台应用程序3(应用程序已被杀死

您不得在向 Firebase API 的请求/应用内输入 JSON 键"通知",而应使用"数据"。

您可以按照文档进行操作。https://firebase.google.com/docs/cloud-messaging/concept-options#notifications

相关内容

  • 没有找到相关文章

最新更新