简体   繁体   English

包含多个群组的Android通知

[英]Android notifications with multiple groups

I implemented "Direct Reply" for the notifications in my app. 我在我的应用中为通知实施了“直接回复”。 How do I implement multiple direct replies? 如何实施多个直接回复?

For example, if the user receives messages from two different people, I want him to be able to reply to each one of them through the notification. 例如,如果用户收到来自两个不同人的消息,我希望他能够通过通知回复他们中的每一个。

Here is my code: 这是我的代码:

notificationBuilder.setContentTitle(title)
                    .setContentText(text);
NotificationCompat.InboxStyle expandedStyle = new NotificationCompat.InboxStyle();
expandedStyle.setBigContentTitle(title);
for (String key : mMessageList.keySet()) {
    for (String message : mMessageList.get(key)) {
        expandedStyle.addLine(message);
    }
}
expandedStyle.setSummaryText(summary);
notificationBuilder.setStyle(expandedStyle);

String replyLabel = context.getString(R.string.reply_to, name);
RemoteInput remoteInput = new RemoteInput.Builder(KEY_TEXT_REPLY)
                .setLabel(replyLabel)
                .build();

NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder(
                R.drawable.reply, replyLabel, getReplyPendingIntent(context))
                .addRemoteInput(remoteInput)
                .build();

notificationBuilder.addAction(replyAction);

NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(NOTIFICATION_ID, notificationBuilder.build());

When creating multiple notifications for a handheld device, you should always aggregate similar notifications into a single summary notification. 为手持设备创建多个通知时,应始终将类似通知聚合到单个摘要通知中。

Check here this shows how to build multiple notification as groups. 点击此处显示如何将多个通知构建为组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM