2011-10-07 10 views
10

Ho visto molti esempi su come far accadere qualcosa quando l'utente fa clic su una notifica ma in realtà non voglio che accada qualcosa. Se l'utente fa clic sulla notifica, desidero semplicemente che la notifica scompaia e che l'utente NON venga portato ovunque.Come scrivere una notifica che non ha assolutamente nulla quando si fa clic?

Nel mio codice qui sotto, mentre FLAG_AUTO_CANCEL cancella la notifica dalla barra di stato, quando l'utente fa clic su una mia notifica, viene portato su "MyActivity".

Come posso creare una notifica che non fa nulla?

Notification notification = new Notification(R.drawable.success, res.getString(R.string.messages_sent), System.currentTimeMillis()); 

     //Define the expanded message and intent 
     Context context = getApplicationContext(); 
     CharSequence contentTitle = res.getString(R.string.messages_sent_ellipsis); 


     Intent notificationIntent = new Intent(this, MyActivity.class); 
     PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); 
     notification.setLatestEventInfo(context, contentTitle, mStrSuccessMessage, contentIntent); 
     notification.flags |= Notification.FLAG_AUTO_CANCEL; 
     //Pass the notification to the notification manager 
     mNotificationManager.notify(1, notification); 
+1

possibile duplicato di [Come posso cancellare una notifica quando l'utente fa clic su di esso?] (Http://stackoverflow.com/questions/7682009/how-can-i-cancel-a-notification-when-the- user-clic-on-it) –

risposta

17

Modifica

Intent notificationIntent = new Intent(this, MyActivity.class); 

a

Intent notificationIntent = new Intent(); 

farebbe il lavoro. L'essenza è se non vuoi niente, dagli un vuoto intento.

Problemi correlati