I want to make a notification with buttons. But after click on button- notification panel is hiding. What shall I do? I'm using this code to create my notification:
public class MyNotification extends Notification {
private Context ctx;
private NotificationManager mNotificationManager;
public MyNotification (Context ctx, int layaut_id) {
super();
this.ctx = ctx;
String ns = Context.NOTIFICATION_SERVICE;
mNotificationManager = (NotificationManager) ctx.getSystemService(ns);
CharSequence tickerText = "Shortcuts";
long when = System.currentTimeMillis();
Notification.Builder builder = new Notification.Builder(ctx);
Notification notification = builder.getNotification();
notification.when = when;
notification.tickerText = tickerText;
notification.icon = R.drawable.ic_launcher;
RemoteViews contentView = new RemoteViews(ctx.getPackageName(), layaut_id);
//set button listners
setListeners(contentView);
notification.contentView = contentView;
notification.flags |= Notification.FLAG_NO_CLEAR;
CharSequence contentTitle = "From Shortcuts";
mNotificationManager.notify(1387, notification);
}
Use setOnClickPendingIntent()
on buttons' views.
setOnClickPendingIntent