Wie wird die Push-Benachrichtigung von Firebase Cloud Messaging auf Textview Android angezeigt?

Ich habe Firebase Cloud Messaging in meiner App implementiert. Ich habe vom Server gesendete Nachrichten auf meinem Gerät als Push-Benachrichtigung empfangen, konnte diese Nachricht jedoch nicht in der Textansicht der App anzeigen. Wie mache ich das?

Hier ist der Code für onMessageReceived ..

     @Override
public void onMessageReceived(RemoteMessage message) {
    String image = message.getNotification().getIcon();
    title = message.getNotification().getTitle();
    text = message.getNotification().getBody();
    String sound = message.getNotification().getSound();

    int id = 0;
    Object obj = message.getData().get("id");
    if (obj != null) {
        id = Integer.valueOf(obj.toString());
    }



    this.sendNotification(new NotificationData(image, id, title, text, sound));

}

private void sendNotification(final NotificationData notificationData) {

    Intent intent = new Intent(this, MainActivity.class);

    intent.putExtra(NotificationData.TEXT, notificationData.getTextMessage());
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);


    NotificationCompat.Builder notificationBuilder = null;
               notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.mipmap.toot)
                .setContentTitle(URLDecoder.decode(notificationData.getTitle(), "UTF-8"))
                .setContentText(URLDecoder.decode(notificationData.getTextMessage(), "UTF-8"))
                .setAutoCancel(true)
                .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                .setContentIntent(pendingIntent);

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    if (notificationBuilder != null) {
        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(notificationData.getId(), notificationBuilder.build());
    } else {
        Log.d(TAG, "Não foi possível criar objeto notificationBuilder");
    }
}

Antworten auf die Frage(4)

Ihre Antwort auf die Frage