我想用按钮发出通知。但点击按钮后 - 通知面板正在隐藏。我该怎么办? 我使用此代码创建了通知:
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);
}
答案 0 :(得分:1)
点击它时,您的通知可能是自动取消的。 要禁用此添加:
builder.setAutoCancel(false);
答案 1 :(得分:1)
在按钮的视图上使用setOnClickPendingIntent()
。
setOnClickPendingIntent