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, contentIntent);
notificationManager.notify(NOTIFY_FAILED, displayErrorNotification);
}
Run Code Online (Sandbox Code Playgroud)
在这个例子中,我使用1来表示失败的通知,但是如果其他程序也使用数字1作为通知.
当我这样做时会发生什么:
notificationManager.cancel(NOTIFY_FAILED);
Run Code Online (Sandbox Code Playgroud)