Вопрос

From the documenation of the NotificationManager in Android:

public void notify (int id, Notification notification) Post a notification to be shown in the status bar. If a notification with the same id has already been posted by your application and has not yet been canceled, it will be replaced by the updated information.

it will be replaced by the updated information.

I don't want the old information to be replaced, I want both notifications. NB: each notification has its own id:

notificationManager.notify(0, notification);
notificationManager.notify(1, notification);

How to do this?

Это было полезно?

Решение

Stack your notifications

If your app creates a notification while another of the same type is still pending, avoid creating an altogether new notification object. Instead, stack the notification.

A stacked notification builds a summary description and allows the user to understand how many notifications of a particular kind are pending.

http://developer.android.com/design/patterns/notifications.html

Другие советы

public void notify (String tag, int id, Notification notification)

Since: API Level 5 Post a notification to be shown in the status bar. If a notification with the same tag and id has already been posted by your application and has not yet been canceled, it will be replaced by the updated information.

Parameters tag A string identifier for this notification. May be null. id An identifier for this notification. The pair (tag, id) must be unique within your application. notification A Notification object describing what to show the user. Must not be null.

Try this one:

private void notifyMe(String message) {
        NotificationManager nManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        NotificationCompat.Builder ncomp = new NotificationCompat.Builder(this);
        ncomp.setContentTitle(getResources().getString(R.string.notification_title));
        ncomp.setContentText(message);
        ncomp.setTicker(getResources().getString(R.string.notification_ticker));
        ncomp.setSmallIcon(R.drawable.ic_launcher);
        ncomp.setAutoCancel(true);      
        //nManager.notify((int) System.currentTimeMillis(), ncomp.build());
        nManager.notify(int(System.currentTimemillisec
), ncomp.build());
    }
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top