1

I want to show firbase notification in only one notification but when per time i send push notification by console or my web service automatic create in the Different notifications. even when I don't use notification builder in my code, and android itself automatic create notification, Eventually I WANT create notification in Inbox style and display all message or title below them, thanks for per your responding and your help!!!

enter code here@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    Log.e(MyApplication.LOG_TAG, "remote Message:" + remoteMessage.toString());
    Log.e(MyApplication.LOG_TAG, "remote Message->(Data):" + remoteMessage.getData().toString());
    Log.i(MyApplication.LOG_TAG, "FROM:" + remoteMessage.getFrom());
    Log.i(MyApplication.LOG_TAG, "MessageID:" + remoteMessage.getMessageId());
    Log.i(MyApplication.LOG_TAG, "MessageType:" + remoteMessage.getMessageType());
    Log.i(MyApplication.LOG_TAG, "To:" + remoteMessage.getTo());
    Log.i(MyApplication.LOG_TAG, "SentTime:" + remoteMessage.getSentTime());
    Log.i(MyApplication.LOG_TAG, "Ttl:" + remoteMessage.getTtl());
    Log.i(MyApplication.LOG_TAG, "CollapseKey:" + remoteMessage.getCollapseKey());
    if (remoteMessage.getNotification() != null) {

        fcm.setTag(remoteMessage.getNotification().getTag());
        fcm.setTitle(remoteMessage.getNotification().getTitle());
        fcm.setBody(remoteMessage.getNotification().getBody());
        fcm.setBodyLocalizationKey(remoteMessage.getNotification().getBodyLocalizationKey());
        fcm.setClickAction(remoteMessage.getNotification().getClickAction());
        fcm.setColor(remoteMessage.getNotification().getColor());
        fcm.setIcon(remoteMessage.getNotification().getIcon());

        Log.i(MyApplication.LOG_TAG, "Notification:" + remoteMessage.getNotification());
        Log.i(MyApplication.LOG_TAG, "Sound:" + remoteMessage.getNotification().getSound());
        Log.i(MyApplication.LOG_TAG, "BodyLocalizationKey:" + remoteMessage.getNotification().getBodyLocalizationKey());
        Log.i(MyApplication.LOG_TAG, "ClickAction:" + remoteMessage.getNotification().getClickAction());
        Log.i(MyApplication.LOG_TAG, "Color:" + remoteMessage.getNotification().getColor());
        Log.i(MyApplication.LOG_TAG, "Icon:" + remoteMessage.getNotification().getIcon());
        Log.i(MyApplication.LOG_TAG, "Tag:" + remoteMessage.getNotification().getTag());
        Log.i(MyApplication.LOG_TAG, "Title:" + remoteMessage.getNotification().getTitle());
        Log.i(MyApplication.LOG_TAG, "Body:" + remoteMessage.getNotification().getBody());
    }
    if (remoteMessage.getData().size() > 0) {
        Log.i(MyApplication.LOG_TAG, "Message data: " + remoteMessage.getData().toString());
        Log.i(MyApplication.LOG_TAG, "Have field=" + remoteMessage.getData().containsKey("MessageID"));
        try {
            JSONObject data = new JSONObject(remoteMessage.getData().toString());
            message = messageParser(data);
        } catch (Exception e) {
            Log.e(MyApplication.LOG_TAG, "Exception: " + e.getMessage());
        }
        MessageClass.LogConsole(message);
        showNotification(message.getTitle)
    }

    public static void showNotification(String Message) {
    Intent intent = new Intent(MyApplication.context, MyBroadcastReceiver.class);
    PendingIntent broadcastIntent = PendingIntent.getBroadcast(MyApplication.context, 0, intent, 0);
    Bitmap icon = BitmapFactory.decodeResource(MyApplication.context.getResources(), R.drawable.shna);
    NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
    MyApplication.preferenceManager.setNotification(Message);
    String oldNotification = MyApplication.preferenceManager.getNotifications();
    Log.e(MyApplication.LOG_TAG, "Notification:" + oldNotification);
    List<String> messages = Arrays.asList(oldNotification.split("\\|"));
    for (int i = messages.size() - 1; i >= 0; i--) {
        inboxStyle.addLine(messages.get(i));
    }
    ShortcutBadger.applyCount(MyApplication.context, messages.size());
    inboxStyle.setSummaryText(messages.size() + " More");
    notification = new NotificationCompat.Builder(MyApplication.context)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setLargeIcon(icon)
            .setWhen(0)
            .setCategory(Notification.CATEGORY_MESSAGE)
            .setGroup(Notification.CATEGORY_MESSAGE)
            .setAutoCancel(true)
            .setDeleteIntent(broadcastIntent)
            .setContentTitle("")
            .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS)
            .setStyle(inboxStyle)
            .build();

    MyApplication.notificationManager.notify(0, notification);
}
public Message messageParser(JSONObject data) {
    Message message = new Message();
    try {
        message.setTitle(data.getJSONObject("data").getString("Title"));
        message.setDated(data.getJSONObject("data").getString("Dated"));
    } catch (JSONException e) {
        Log.e(MyApplication.LOG_TAG, "Json Exception: " + e.getMessage());
        return null;
    } catch (Exception e) {
        Log.e(MyApplication.LOG_TAG, "Exception: " + e.getMessage());
        return null;
    }
    return message;
}

}
AL.
  • 36,815
  • 10
  • 142
  • 281
Saleh
  • 13
  • 6
  • @Frank van Puffelen: Thank you Frank, Don't you have idea or guidance or advise or ...!!!? – Saleh May 15 '17 at 14:27

1 Answers1

2

You could use the tag for the notification payload:

Identifier used to replace existing notifications in the notification drawer.

If not specified, each request creates a new notification.

If specified and a notification with the same tag is already being shown, the new notification replaces the existing one in the notification drawer.

However, note that you won't be able to set the value for tag when you send the message from the Firebase Console.

Or you could just bundle the notifications yourself.

Community
  • 1
  • 1
AL.
  • 36,815
  • 10
  • 142
  • 281
  • You'rr welcome Saleh. If you think this sufficiently answered your question, do click the *check mark* at the left side to mark it as accepted. Cheers! :) – AL. May 15 '17 at 16:03
  • Excuse me @AL. dear, Unfortunately I have to say you my problem be exist, and I couldn't create Inbox style and show it, although fortunately one of the my problems is solved by help and guidance you!!! I Couldn't show and create inbox style and print all message context blow them and one notification!!! – Saleh May 15 '17 at 18:44
  • Hi Saleh. I would suggest posting a different question along with the details and the code snippet you have so far, so that the community would be able to look into it, and help you out more. :) – AL. May 16 '17 at 01:29
  • Hello Dear AL and My dear my friend please if you have time and feel lool at this link:https://stackoverflow.com/questions/44185154/implement-app-chat-with-firebase-cloud-message – Saleh May 25 '17 at 16:21