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">
<intent-filter>
<action android:name="action.cancel.notification"/>
</intent-filter>
</receiver>
After that, to the pictureView add the pendingIntnet as,
pictureView.setOnClickPendingIntent(R.id.button, 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
     }
   }
}

Comments

Popular posts from this blog

AlarmManager and Notification in Android

Swipe Action and ViewFlipper in Android

Open Gallery and get the selected image in appplication