Bob
Bob

Reputation: 23000

Notification alert is shown only for the first message

I have the following method for showing notifications:

private void sendNotification(String msg) {
        mNotificationManager = (NotificationManager)
                _context.getSystemService(Context.NOTIFICATION_SERVICE);

        Notification notification = new Notification(R.drawable.menu_cartable,
                "you have a new message",
                System.currentTimeMillis());
        notification.flags = Notification.FLAG_AUTO_CANCEL;
        notification.sound = RingtoneManager
                .getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        Intent notificationIntent = new Intent(_context, ActCartable.class);
        PendingIntent intent = PendingIntent.getActivity(_context, 0,
                    notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);

        notification.setLatestEventInfo(_context,
                "you have a new message",
                msg,
                intent);

        mNotificationManager.notify(NOTIFICATION_ID, notification);

    }

enter image description here enter image description here

In Android 4.2 When a message is received for the first time (notification bar is cleared), a big icon (tickerText) is shown in notification bar and a few seconds later it is hidden and notification goes to notification bar. If I do not open that notification (notification bar is not cleared) and the second messaged is received, the big icon is not shown again but device makes the sound correctly and the content of the new message is updated successfully in notification bar if the user open the notification bar.

You should know that the big icon is shown all time in android 3.x.

How can I show that big icon in android 4.x each time a new message is received and notification bar is not cleared?

Upvotes: 0

Views: 1060

Answers (1)

Bracadabra
Bracadabra

Reputation: 3659

For example, you can cancel old notification and display a new one with another id. It will look like this:

mNotificationManager.cancel(notificationId);
mNotificationManager.notify(notificationId++, notification);

Update by @breceivemail:

It works correctly if you put ++ before notificationId like this:

 mNotificationManager.cancel(notificationId);
 mNotificationManager.notify(++notificationId, notification);

Thanks,

Upvotes: 1

Related Questions