Cancel a Notification From addAction Button

I want to Dismiss a notification by using action button so that notification gets dismiss one action and opens details of it on another action.

PendingIntent pIntentForInformation = PendingIntent.getActivity(this, 0, intentInformation,PendingIntent.FLAG_UPDATE_CURRENT);
//PendingIntent pendingIntentForClose = PendingIntent.getActivity(this, 0, intentClose,PendingIntent.FLAG_CANCEL_CURRENT);

//Using NotificationCompactBuilder
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)  // Icon Big One On Left Hand Side
.setTicker(getString(R.string.notificationticker)) //Ticker on Status Bar
.setContentTitle(getString(R.string.notificationtitle)) //Title of Notification
.setContentText(getString(R.string.notificationtext)) //Text for Notification
.addAction(R.drawable.info, "Details", pIntentForInformation) //Action Button icon
.addAction(R.drawable.close, "Dismiss",pIntentForInformation)
.setContentIntent(pIntentForInformation)
.setAutoCancel(true);

// Create Notification Manager
NotificationManager notificationmanager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationmanager.notify(0, builder.build());


Source: android

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.