单击后如何使通知消失

时间:2017-01-25 11:59:57

标签: java android

我希望点击后通知消失,我不想去新的活动。这是我建立通知的方式:

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

}

1 个答案:

答案 0 :(得分:0)

我改变了这个:

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

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

并且有效