With multiple notifications, the second notification displayed in Android minimize mode

I am showing several notifications in my android app.

When there is one notification, it is displayed correctly.

enter image description here

But when I create the second notification, the second notification is shown in collapse by default.

enter image description here

If I manually expand the second notification, it displays as:

enter image description here

I want to show notifications in advanced 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 is something wrong?

Thanks in advance.

+4
source share
1 answer

I solved it. I did not set ContentTitle and ContentText for failure 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());
0
source

Source: https://habr.com/ru/post/1679614/


All Articles