2013-02-12 22 views
20

ho creato una notifica barra di stato di Android in Android a livello di codice utilizzando il codice indicato di seguito con un particolare idCome Congeda/Cancellare la notifica barra di stato in programmazione

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

     } 

Ora quello che voglio è rimuovere questa notifica su facendo clic su un pulsante nell'applicazione in modo programmatico.

Come posso ottenere questo?

risposta

52

È possibile utilizzare questo:

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

Utilizzare lo stesso ID utilizzato durante la notifica

myNotificationManager.cancel(NOTIFICATION_ID) 
7

myNotificationManager.cancelAll();

+1

Questo è quello che volevo :) – styler1972

Problemi correlati