Android 如何在生成器通知中设置正在进行的标志?

Android 如何在生成器通知中设置正在进行的标志?,android,Android,如何在使用notification.BuilderBuilder创建的通知中添加标志?将标志添加到Notification noti=new NotificationCompat.Builder(this)通知声明中很简单,但不添加到我上面提到的通知声明中。以下是我到目前为止所做的尝试: Notification.Builder builder = new Notification.Builder(this) .setSmallIcon(R.drawable.ic_launcher)

如何在使用
notification.Builder
Builder创建的通知中添加标志?将标志添加到
Notification noti=new NotificationCompat.Builder(this)
通知声明中很简单,但不添加到我上面提到的通知声明中。以下是我到目前为止所做的尝试:

Notification.Builder builder = new Notification.Builder(this)
    .setSmallIcon(R.drawable.ic_launcher)
    .setContentTitle("Download [ROOT]")
    //.setContentText("This is a test notification")
    .setAutoCancel(false).setOngoing(true);
Intent notificationIntent = new Intent(this, NotificationAction.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
    notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(contentIntent);
// Add as notification
NotificationManager manager = (NotificationManager) 
    getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(111, builder.build());
要将setContinuous()设置为Notification.Builder,请尝试以下操作:

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setContentIntent(generatePendingIntent("Notification Type"))
.setAutoCancel(true)
.setOngoing(true/false); // this is where you have to set
您也可以使用Notification.Builder,但使用NotificationCompat.Builder,在Android 4.1及更高版本中,您可以根据扩展的通知设置
操作按钮


以及如何处理单击通知方法时发生的情况:

private PendingIntent generatePendingIntent(String type) {
    PendingIntent pendingIntent;
    Intent notificationIntent;
    if (type.equals("link")) {
        notificationIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        pendingIntent = PendingIntent.getActivity(context.getApplicationContext(), 0, notificationIntent, 0);
    } else {
        notificationIntent = new Intent(context, DesiredActivity.class);
        notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        pendingIntent =
                PendingIntent.getActivity(context.getApplicationContext(), 0, notificationIntent, 0);
    }
    return pendingIntent;
}