简体   繁体   中英

With multiple notifications second notification showing in collapse mode Android

I'm showing multiple notifications in my android application.

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.

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());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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