how to display message of push notification from firebase cloud messaging on textview android

前端 未结 2 952
深忆病人
深忆病人 2021-01-21 11:16

I have implemented firebase cloud messaging in my app. I have been receiving messages sent from server in my device as a push notification but I have not been able to display th

2条回答
  •  灰色年华
    2021-01-21 11:46

    private void handleNotification(String message) {
            if (!NotificationUtils.isAppIsInBackground(getApplicationContext())) {
                // app is in foreground, broadcast the push message
                Intent pushNotification = new Intent(Config.PUSH_NOTIFICATION);
                pushNotification.putExtra("message", message);
                LocalBroadcastManager.getInstance(this).sendBroadcast(pushNotification);
    
                // play notification sound
                NotificationUtils notificationUtils = new NotificationUtils(getApplicationContext());
                notificationUtils.playNotificationSound();
            }else{
                // If the app is in background, firebase itself handles the notification
            }
        }
    

提交回复
热议问题