본문 바로가기
프로그래밍 놀이터/안드로이드, Java

[android] Messaging Style Notification Tutorial

by 돼지왕 왕돼지 2018. 3. 1.
반응형


https://blog.stylingandroid.com/nougat-messaging-style-notifications/

addMessage, Android, Bundled Notification, code 분기, Framework, grouping, message, messaging style, messaging style notification, MessagingStyle, notification, notificationCompat, NotificationCompat.MessagingStyle, NotificationCompay, nougat, nougat 이하 버전, setConversationTitle, tutorial, [android] Messaging Style Notification Tutorial


-

Bundled Notification 이란 녀석은 Notification 들을 각각 만들고, Notification framework 를 사용하여 grouping 을 하는 개념이라면,

Messaging Style Notification 은 Notification 하나에 여러 Message 를 담는 것을 의미한다.


messaging-style-cropped


-

Messaging Style Notification 은 Nougat 부터 사용 가능하다.



-

NotificationCompay.MessagingStyle messagingStyle = buildMessageList(messages);

Notification notification = new NotificationCompat.Builder(context)

    .setStyle(messagingStyle)

    .setSmallIcon(R.drawable.ic_message)

    .build();

notificationManager.notify(NOTI_ID, notification);


private NotificationCompat.MessagingStyle buildMessageList(List<String> messages){

    NotificationCompat.MessagingStyle messagingStyle = new NotificationCompat.MessagingStyle(DISPLAY_NAME)

    .setConversationTitle(“Messenger”); // 상단에 표시된다.

    for (String message : messages){

        messagingStyle.addMessage(message, System.currentTimeInMillies(), SENDER_NAME);

    }

    return messagingStyle;

}



-

Messaging Styling 을 사용하게 되면 Nougat 이전 버전에서는 아래와 같이 표시된다.

따라서 코드 분기가 필요하다.

messaging-style-legacy-cropped







반응형

댓글