public static final int NOTIFY_FAILED = 1;
private final Notification displayErrorNotification = new Notification(R.drawable.notification, "Communication Error", System.currentTimeMillis());
private void displayNotificationError(String message) {
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(), 0);
displayErrorNotification.number++;
displayErrorNotification.setLatestEventInfo(getApplicationContext(), "Failed x ("+displayErrorNotification.number+")", message, content开发者_运维问答Intent);
notificationManager.notify(NOTIFY_FAILED, displayErrorNotification);
}
In this example I have used 1 for failed notifications but what if other programs also use the number 1 for their notifications.
What would happen when I do this:
notificationManager.cancel(NOTIFY_FAILED);
You can use any number you like.
The IDs and Notifications are per-application — you do not need to worry about other applications changing or cancelling your notifications.
Actually the place where this might help is if your application has different categories of notifications.
Example: Let us consider u have two categories A and B. You assign two ID's to them. Now if your app gives a notification for A and B [or A after B], you will find that there are two notifications. But say your app sends out two notifications of category A, only the latest one will be displayed.
精彩评论