Java 如何在单击后使通知消失

Java 如何在单击后使通知消失,java,android,Java,Android,我想在单击后使通知消失,我不想进入新活动。以下是我构建通知的方式: public static void getSynchronizeNotification(Context context, DataResponse dataResponse){ Bitmap Largeicon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher); NotificationManager

我想在单击后使通知消失,我不想进入新活动。以下是我构建通知的方式:

public static void getSynchronizeNotification(Context context, DataResponse dataResponse){
    Bitmap Largeicon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher);
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.cancel(NOTIFICATION_SYNCHRONIZE_ID);

Intent in = new Intent(String.valueOf(context));
Intent intent = new Intent(context, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, in, 0);
Notification notification  = new Notification.Builder(context)
        .setContentTitle(context.getString(R.string.app_name))
        .setSmallIcon(R.drawable.ic_launcher)
        .setContentIntent(pendingIntent)
        .setContentText("Zmiany po synchronizacji...")
        .setStyle(new Notification.BigTextStyle().bigText(buildNotificationAfterSynchronizeText(dataResponse)))
        .setLargeIcon(Largeicon)
        .setAutoCancel(true)
        .setVibrate(vibratePattern)
        .setSound(alarmSound)
        .setPriority(Notification.PRIORITY_MAX)
        .build();
notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(NOTIFICATION_SYNCHRONIZE_ID, notification);
}

我改变了这一点:

PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, in, 0);
pendingent pendingent=pendingent.getActivity(context,0,new Intent(),0)


它可以工作

删除setContentIntent(pendingIntent)有帮助吗?@KarthikCP当我点击一个通知时,它不会发生,当我刷卡时通知消失