简体   繁体   中英

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

    }

在此处输入图片说明在此处输入图片说明

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?

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,

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