我想用按钮发出通知。但是,单击按钮后,通知面板将隐藏。我该怎么办?
我正在使用以下代码创建通知:

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);

}

最佳答案

在按钮的视图上使用setOnClickPendingIntent()
setOnClickPendingIntent

09-10 01:03
查看更多