【问题标题】:How to fix FirebaseNotifications如何修复 Firebase 通知
【发布时间】:2019-04-03 08:08:44
【问题描述】:

我已经正确实现了 Fire base 通知,一些设备没有收到 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());

  }

【问题讨论】:

    标签: android push-notification firebase-cloud-messaging build.gradle android-push-notification


    【解决方案1】:

    您需要为此添加频道

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

    【讨论】:

      【解决方案2】:

      未收到通知!

      在以下情况下让 firebase 调用你的 onMessageReceived()

      1) 前台应用 2)后台应用 3) 应用已被杀死

      您不得在您的请求/InApp 中将 JSON 密钥“通知”放入 firebase API,而应使用“数据”。

      您可以关注文档。 https://firebase.google.com/docs/cloud-messaging/concept-options#notifications

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-04-30
        • 1970-01-01
        • 1970-01-01
        • 2021-12-12
        • 2016-10-27
        • 1970-01-01
        相关资源
        最近更新 更多