title: Android studio FCM firebase notification problem with app foreground
body: <p>I have a problem with notifications from FCM firebase not always showing in my android studio app. Here is my code that is supposed to be read when the app receive the notification :</p>
  <pre><code>public class PushNotificationService extends FirebaseMessagingService {
  
      @Override
      public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
  
          Log.d(&quot;debug&quot;, &quot;received&quot;);
  
          super.onMessageReceived(remoteMessage);
          String title = remoteMessage.getNotification().getTitle();
          String body = remoteMessage.getNotification().getBody();
          final String CHANNEL_ID = &quot;HEADS_UP_NOTIFICATIONS&quot;;
          NotificationChannel channel = new NotificationChannel(CHANNEL_ID,
                  &quot;myNotification&quot;,
                  NotificationManager.IMPORTANCE_HIGH);
          getSystemService(NotificationManager.class).createNotificationChannel(channel);
  
          Notification.Builder notification = new Notification.Builder(this, CHANNEL_ID)
                  .setContentTitle(title)
                  .setContentText(body)
                  .setAutoCancel(true) //  pour faire disparaitre notif qd click dessus
                  .setSmallIcon(R.drawable.round_forest_24); // pour changer icone notif
  
          NotificationManagerCompat.from(this).notify(1, notification.build());
      }
  }
  </code></pre>
  <p>I'm doing tests on my phone not emulator, by sending immediate notification from FCM. I always observe the same behavior :</p>
  <p>If the app is closed or in background, the notification shows up, when I click on it the app open and the notification disappear. I never see the &quot;received&quot; in the log and the small icon is not the one I putted so I doubt my code is read.</p>
  <p>If the app is in foreground, the notification shows up with the correct icon and the &quot;received&quot; appear in the log. However, if I click on the notification nothing happend and the notification don't disappear.</p>
  <p>In both case I have no error.. I would like to be able to have my code read in both case (with the icon that I choosed) and the notification to disappear on click. How can I achieve that please ?</p>