简体   繁体   English

使用多个通知第二个通知显示在崩溃模式Android

[英]With multiple notifications second notification showing in collapse mode Android

I'm showing multiple notifications in my android application. 我在我的Android应用程序中显示多个通知。

When there is single notification it is showing correctly. 当有单一通知时,它正确显示。

在此输入图像描述

But when I generate second notification, second notification showing in collapse by default. 但是当我生成第二个通知时,默认情况下显示崩溃的第二个通知。

在此输入图像描述

If I manually expand second notification it is showing as: 如果我手动展开第二个通知,它显示为:

在此输入图像描述

I want to show a notifications in expanded mode by default. 我想默认以扩展模式显示通知。

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

int num = (int) System.currentTimeMillis();

        PendingIntent pendingIntent = PendingIntent.getActivity(this, num  /* Request code */, intent,
                PendingIntent.FLAG_ONE_SHOT);


        NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
        bigTextStyle.setBigContentTitle(title);
        bigTextStyle.bigText(messageBody);

        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.corco)
                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setStyle(bigTextStyle)
                .setContentIntent(pendingIntent);

        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(num  /* ID of notification */, notificationBuilder.build());

Am i missing something? 我错过了什么吗? or doing something wrong? 或做错了什么?

Thanks in advance. 提前致谢。

I resolved it. 我解决了 I was not setting any ContentTitle and ContentText for collapse notification. 我没有为崩溃通知设置任何ContentTitle和ContentText。

Here is my updated code: 这是我更新的代码:

int num = (int) System.currentTimeMillis();

        PendingIntent pendingIntent = PendingIntent.getActivity(this, num  /* Request code */, intent,
                PendingIntent.FLAG_ONE_SHOT);


        NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
        bigTextStyle.setBigContentTitle(title);
        bigTextStyle.bigText(messageBody);

        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.corco)
                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setStyle(bigTextStyle)
                .setContentTitle(title)
                .setContentText(messageBody)
                .setContentIntent(pendingIntent);

        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(num  /* ID of notification */, notificationBuilder.build());

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

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