Uma Achanta Uma Achanta - 1 year ago 213
Android Question

How to handle the fire base notification when app is in foreground

I have integrated Fire base cloud messaging with my application.
When I was sending notification from firebase console, If app is in background/not opened then I am receiving notification,

but unable to receive notification when app is in foreground/open

all suggestions are appreciated.

Answer Source

When app is in foreground,notifications are not generated need to write some additional code.when message is received onMessagereceived method is called where you can generate the is the code:

public class MyFirebaseMessagingService extends FirebaseMessagingService {
public void onMessageReceived(RemoteMessage remoteMessage) {
    Log.d("msg", "onMessageReceived: " + remoteMessage.getData().get("message"));
    NotificationCompat.Builder builder = new  NotificationCompat.Builder(this)
NotificationManager manager = (NotificationManager)     getSystemService(NOTIFICATION_SERVICE);