如何阻止通知面板隐藏?
How to stop notification panel from hiding?
我想用按钮发出通知。但是在点击按钮后-通知面板被隐藏了。我该怎么办?
我正在使用此代码创建我的通知:
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);
}
可能您的通知在您单击时自动取消。
要禁用此添加:
builder.setAutoCancel(false);
在按钮的视图上使用 setOnClickPendingIntent()
。
setOnClickPendingIntent
我想用按钮发出通知。但是在点击按钮后-通知面板被隐藏了。我该怎么办? 我正在使用此代码创建我的通知:
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);
}
可能您的通知在您单击时自动取消。 要禁用此添加:
builder.setAutoCancel(false);
在按钮的视图上使用 setOnClickPendingIntent()
。
setOnClickPendingIntent