取消在Activity中无法取消特定的Push通知android

时间:2017-10-09 09:23:23

标签: android push-notification

我在Service课程中显示了Android中的推送通知,如果我们点击完整的Remoteview但是当我打开{Activity时显示正常并获得解雇1}}来自RemoteView的按钮/文字,通知不会被取消。

在服务中:

Intent notificationRecordFollowupintent = new Intent(this, RecordFollowUpActivity.class);
notificationRecordFollowupintent.putExtra("notify_id", m);
PendingIntent contentRecordFollowupIntent = PendingIntent.getActivity(this, m, notificationRecordFollowupintent, PendingIntent.FLAG_UPDATE_CURRENT);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        builder.setSmallIcon(R.mipmap.ic_launcher)
                .setWhen(System.currentTimeMillis())
                .setDefaults(NotificationCompat.DEFAULT_SOUND)
                .setStyle(bigTextStyle)
                .setCustomBigContentView(contentView)
                .setCustomContentView(contentView)
                .setGroup("Follow Up Alert")
                .setNumber(++numMessages)
                .setOngoing(true)
                .setAutoCancel(true)
                .setContentIntent(contentRecordFollowupIntent);
    } else {
        builder.setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle("Follow Up Alert")
                .setContentText("" + name)
                .setWhen(System.currentTimeMillis())
                .setDefaults(NotificationCompat.DEFAULT_SOUND)
                .setStyle(bigTextStyle)
                .setCustomContentView(contentView)
                .setCustomBigContentView(contentView)
                .setContentIntent(contentRecordFollowupIntent)
                .setAutoCancel(true);

    }

    Notification notification = builder.build();
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    nm.notify(getResources().getString(R.string.app_name), m, notification);

活动:

 Intent intent = getIntent();
    int notificationId = intent.getIntExtra("notify_id", -1);
    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.cancel(notificationId);

我得到同样的ID,但它仍然没有被取消。

1 个答案:

答案 0 :(得分:-1)

NotificationManager.cancelAll()删除所有通知。 NotificationManager.cancel(notificationId)删除特定通知。