1

I want to close the notification by setAutoCancle() method. Here is code of NotifactionExample.

@SuppressWarnings("deprecation")
protected void notifactionAlert() {
    // TODO Auto-generated method stub

    NotificationManager myNotifaction = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    @SuppressWarnings("deprecation")
    Notification Notifaction = new Notification(R.drawable.notifaction,
            "Notifaction received.", System.currentTimeMillis());


    Intent notifactionIntent = new Intent(MainActivity.this, notify.class);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
            notifactionIntent, 0);
    Notifaction.setLatestEventInfo(MainActivity.this, "Notifaction.",
            "you get a new notifaction...", pendingIntent);
    myNotifaction.notify(9999, Notifaction);

}

What can I do?

Murtaza Khursheed Hussain
  • 15,176
  • 7
  • 58
  • 83
Sohaib Raza
  • 41
  • 2
  • 10

3 Answers3

0

All you need to do is set the autoCancel Flag On.

Notifaction.flags |= Notification.FLAG_AUTO_CANCEL
mayank
  • 543
  • 4
  • 14
0

Try it onclick of any button:

@Override
    public void onClick(View v) {
        Intent intent = new Intent();
        PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
        Notification noti = new Notification.Builder(this)
        .setTicker("Ticker Title")
        .setContentTitle("Content Title")
        .setContentText("Notification content.")
        .setSmallIcon(R.drawable.ic_launcher)
        .setContentIntent(pIntent).getNotification();
        noti.flags=Notification.FLAG_AUTO_CANCEL;
        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationManager.notify(0, noti); 
    }
Androider
  • 3,833
  • 2
  • 14
  • 24
0
Notification notification = new Notification(icon, tickerText, when);
notification.flags = Notification.FLAG_ONGOING_EVENT;

Also you can check, FLAG_NO_CLEAR

Akash
  • 681
  • 3
  • 17