2013-02-12 9 views
20

ich eine Statusleiste Benachrichtigung in android erstellt haben programmatisch den Code mit einer bestimmten ID unten angegebenenWie Entlassen/Abbrechen der Statusleiste Benachrichtigung in android programmatisch

Notification notification; 
    public static NotificationManager myNotificationManager; 
    public static final int NOTIFICATION_ID = 1; 

private static void createStatusBarNotification(Context context,CharSequence NotificationTicket, CharSequence NotificationTitle,CharSequence NotificationContent, int icon) { 
      myNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
      long when = System.currentTimeMillis(); 
      notification = new Notification(icon, NotificationTicket, when); 
      Intent notificationIntent = new Intent(context, MyActivity.class); 
      PendingIntent contentIntent = PendingIntent.getActivity(context, 0,notificationIntent, 0); 
      notification.setLatestEventInfo(context, NotificationTitle,NotificationContent, contentIntent); 
      notification.flags |= Notification.FLAG_ONGOING_EVENT; 
      myNotificationManager.notify(NOTIFICATION_ID, notification); 

     } 

Jetzt möchte, was ich auf diese Benachrichtigung entfernen Klicken eines Buttons in der Anwendung programmatisch.

Wie kann ich das erreichen?

Antwort

52

Benachrichtigung können Sie verwenden:

public void clearNotification() { 
    NotificationManager notificationManager = (NotificationManager) mContext 
      .getSystemService(Context.NOTIFICATION_SERVICE); 
    notificationManager.cancel(NOTIFICATION_ID); 
} 
4

die gleiche ID verwenden, wie verwendet, während

myNotificationManager.cancel(NOTIFICATION_ID) 
7

myNotificationManager.cancelAll();

+1

Das ist was ich wollte :) – styler1972

Verwandte Themen