0

I have implemented Fire base notifications properly some devices not receiving notifications vivo,infocus while running background how to resolve that issue

 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());

  }
EdChum
  • 376,765
  • 198
  • 813
  • 562

2 Answers2

0

You need to add channel for this

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            notificationManager.createNotificationChannel(
                NotificationChannel(
                    "YOUR_ID",
                    "YOUR_NAME",
                    NotificationManager.IMPORTANCE_HIGH
                )
            )
        }
John Joe
  • 12,412
  • 16
  • 70
  • 135
0

Notification not received!

To make firebase to call your onMessageReceived() in the following cases

1) App in foreground 2) App in background 3) App has been killed

you must not put JSON key 'notification' in your request/InApp to firebase API but instead use 'data'.

You can follow the doc. https://firebase.google.com/docs/cloud-messaging/concept-options#notifications

Waheed Nazir
  • 584
  • 7
  • 11