I'm trying to display an notification with firebase when the app is in the foreground. The onMessageReceived method is called when I push the notification from the server, but the notification is not displayed.
Here my code :
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(final RemoteMessage remoteMessage) {
Timber.d("FCM-From: " + remoteMessage.getFrom());
new Handler(Looper.getMainLooper()).post(new Runnable() {
public void run() {
if (remoteMessage.getNotification() != null) {
Timber.d("FCM-Message Notification Body: " + remoteMessage.getNotification().getBody());
NotificationCompat.Builder builder = new NotificationCompat.Builder(
getApplicationContext(), "CHANNEL_NOTIF")
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("test")
.setContentText("test content");
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if (manager != null) {
Timber.d("FCM-Notif");
manager.notify(1, builder.build());
}
}
}
});
}
}
In my logcat I can see :
FCM-Message Notification Body: 202018105166
FCM-From: 1049809400953
FCM-Notif
I followed https://developer.android.com/training/notify-user/build-notification.html#builder
I'am running on Oreo
SOLUTION
Found the answer here : Android foreground service notification not showing
It was an Oreo issue, thank to @Yashaswi N P