Android 通知没有堆叠?

Android 通知没有堆叠?,android,android-notifications,Android,Android Notifications,嗨,我正在使用Firebase云消息服务进行通知。我可以显示通知,但它们没有堆积起来。无论通知数量有多大,它们都会单独显示在通知托盘上。我对单个通知和摘要通知使用相同的组id。有人能帮忙吗 这是我的密码 public class MyFirebaseMessagingService extends FirebaseMessagingService { final String STORY_GROUP = "story"; String groupId; Notificat

嗨,我正在使用Firebase云消息服务进行通知。我可以显示通知,但它们没有堆积起来。无论通知数量有多大,它们都会单独显示在通知托盘上。我对单个通知和摘要通知使用相同的组id。有人能帮忙吗

这是我的密码

public class MyFirebaseMessagingService extends FirebaseMessagingService {
    final String STORY_GROUP = "story";
    String groupId;
    NotificationManagerCompat manager;

    public MyFirebaseMessagingService() {
    }

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);
        if (remoteMessage.getData().size() > 0) {

            Intent intent;
            Map<String, String> data = remoteMessage.getData();
            String notificationFor = data.get("notificationFor");
            String key, ownerId, picUrl, title, body,sendersUid, receiversUid, profilePicUrl, conversationId;

            if (notificationFor.equals("storyComment")) {
                key = data.get("key");
                ownerId = data.get("ownerId");
                picUrl = data.get("icon");
                title = data.get("title");
                body = data.get("body");
                groupId = STORY_GROUP;

                intent = new Intent(this, StoryDetails.class);
                intent.putExtra("key", key);
                intent.putExtra("ownerId", ownerId);

                sendNotification(intent,title,body,groupId,"New comments on your story");

           }

            Log.d("MessagingService", "Message received and has data payload :" + remoteMessage.getData());

        }

    }

    public void sendNotification(Intent intent,String title,String message,String groupId,String summaryText) {

        NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle().setSummaryText(summaryText);

        Log.d("NotificationService","groupId = " + groupId);

        PendingIntent pIntent = PendingIntent.getActivity(this,(int) System.currentTimeMillis(),intent,0);
        Uri notificationSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                                         .setShowWhen(true)
                                         .setContentTitle(title)
                                         .setContentText(message)
                                         .setSmallIcon(R.drawable.launcher)
                                         .setContentIntent(pIntent)
                                         .setGroup(groupId)
                                         .setAutoCancel(true)
                                         .setSound(notificationSound);

        NotificationCompat.Builder group = new NotificationCompat.Builder(this)
                                         .setGroupSummary(true)
                                         .setGroup(groupId);

        Random rand = new Random();
        int randomInt = rand.nextInt(100);
        if (manager == null) {
            manager = NotificationManagerCompat.from(this);
        }
        manager.notify(randomInt,builder.build());
        manager.notify(1,group.build());
   }
}
公共类MyFirebaseMessagingService扩展了FirebaseMessagingService{
最后一个字符串STORY\u GROUP=“STORY”;
字符串组ID;
通知经理公司经理;
公共MyFirebaseMessagingService(){
}
@凌驾
收到消息时公共无效(RemoteMessage RemoteMessage){
super.onMessageReceived(remoteMessage);
如果(remoteMessage.getData().size()>0){
意图;
Map data=remoteMessage.getData();
字符串notificationFor=data.get(“notificationFor”);
字符串键、所有者ID、picUrl、标题、正文、发送者UID、接收者ID、profilePicUrl、会话ID;
if(notificationFor.equals(“故事注释”)){
key=data.get(“key”);
ownerId=data.get(“ownerId”);
picUrl=data.get(“图标”);
title=data.get(“title”);
body=data.get(“body”);
groupId=故事组;
intent=新的intent(这个,StoryDetails.class);
意图。putExtra(“键”,键);
意向。putExtra(“ownerId”,ownerId);
sendNotification(意图、标题、正文、groupId,“对您的故事的新评论”);
}
Log.d(“MessagingService”,“消息已接收并具有数据负载:”+remoteMessage.getData());
}
}
公共void sendNotification(意图、字符串标题、字符串消息、字符串组ID、字符串摘要文本){
NotificationCompat.InboxStyle InboxStyle=新建NotificationCompat.InboxStyle().setSummaryText(summaryText);
Log.d(“NotificationService”、“groupId=“+groupId”);
PendingEvent pIntent=PendingEvent.getActivity(this,(int)System.currentTimeMillis(),intent,0);
Uri notificationSound=RingtoneManager.getDefaultUri(RingtoneManager.TYPE_通知);
NotificationCompat.Builder=新建NotificationCompat.Builder(此)
.setShowWhen(真)
.setContentTitle(标题)
.setContentText(消息)
.setSmallIcon(右可牵引发射器)
.setContentIntent(pIntent)
.setGroup(groupId)
.setAutoCancel(真)
.setSound(通知声音);
NotificationCompat.Builder组=新建NotificationCompat.Builder(此)
.setGroupSummary(真)
.setGroup(groupId);
Random rand=新的Random();
int randomInt=rand.nextInt(100);
if(manager==null){
manager=通知ManagerCompat.from(本);
}
manager.notify(randomInt,builder.build());
manager.notify(1,group.build());
}
}