I have implemented firebase cloud messaging in my app. I have been receiving messages I want to display that message in the textview of the app.
Here is the code to handle onMessageReceived..
public class FcmMessagingService extends FirebaseMessagingService {
private Map<String, String> data;
private static final String TAG="MyFirebaseMsgService";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
data=remoteMessage.getData();
String message=data.get("message");
String titledata=data.get("title");
ManualNotification(titledata , message);
}
private void ManualNotification(String title , String messageBody){
Intent intent = new Intent(this, MainActivity.class);
Bundle bundle = new Bundle();
bundle.putString("message", messageBody);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
Bitmap bmp = BitmapFactory.decodeResource(this.getResources(),R.drawable.splash_img);
Notification.BigPictureStyle bigpicture = new Notification.BigPictureStyle();
bigpicture.bigPicture(bmp);
NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notifaction)
.setContentTitle(title)
//.setContentText(messageBody)
.setLargeIcon(bmp)
.setContentIntent(pendingIntent)
.setStyle(new NotificationCompat.BigTextStyle().bigText(messageBody))
.setContentText(messageBody).setLights(Color.YELLOW, 300, 300)
.setVibrate(new long[] { 100, 250 })
.setDefaults(Notification.DEFAULT_SOUND)
.setAutoCancel(true);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
}