Add Button and onClick on Custom Notification in Android

Add a broadcast receiver with action and pass the Intent with action to PendingIntent The code snippet is as follows,
Intent intent = new Intent("action.cancel.notification");
PendingIntent pi = PendingIntent.getBroadCast(this, id, intent, PendingIntent.FLAG_UPDATE_CUREENT);
Also add the receiver in manifest
<receiver android:name="CancelNotificationReceiver">
<action android:name="action.cancel.notification"/>
After that, to the pictureView add the pendingIntnet as,
pictureView.setOnClickPendingIntent(, pi);
The last part is define the receiver class as,
public class CancelNotificationReceiver extends Broadcastreceiver {
   public void onReceive(Context context, Intent intent) {
     if ("action.cancel.notification".equalsIgnoreCase(intent.getAction())) {
        // .. do what ever you want


Popular posts from this blog

Open Gallery and get the selected image in appplication

AlarmManager and Notification in Android

Dismiss or Cancel dialog by swipe gesture