Я пытаюсь создать уведомление с кнопкой отмены, но когда я нажимаю на него, ничего не происходит. Это мой код:Android: Как создать уведомление с кнопкой отмены?
private NotificationCompat.Builder notificationBuilder;
public void createNotification() {
notificationBuilder = new NotificationCompat.Builder(service);
notificationBuilder.setProgress(100, 0, false);
notificationBuilder.setAutoCancel(true);
Intent intent = OrderProcessingService_.intent(service).actionCancelUpload(basket.getPhotobook_id()).get();
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getService(service, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
notificationBuilder.setContentIntent(pendingIntent);
notificationBuilder.setSmallIcon(R.drawable.ic_action_file_cloud_upload);
NotificationCompat.Action cancelAction = new NotificationCompat.Action(R.drawable.ic_action_navigation_close, service.getString(R.string.cancel_upload), pendingIntent);
notificationBuilder.setContentTitle(service.getString(R.string.notification_upload_title));
notificationBuilder.setContentText(service.getString(R.string.notification_uploading_subtext, Util.getTitle(basket.getPhotobook())));
notificationBuilder.addAction(cancelAction);
addBigPicture(notificationBuilder);
service.startForeground(1, notificationBuilder.build());
}
Изменить эту строку notificationBuilder.addAction (cancelAction); to notificationBuilder.setDeleteIntent (cancelAction); и скажите мне, что вы получите – penta
Если изменение notificationBuilder.addAction (cancelAction); to notificationBuilder.setDeleteIntent (cancelAction); У меня больше нет кнопки отмены. И я не добавил событие onClick() к кнопке, я думал, что это не обязательно с флагом autoCancel = true. – IrApp
Извините, что я отредактировал свои вопросы, потому что я не включил последнюю строку. Я думаю, проблема в том, что уведомление отменяется, но на переднем плане намерение все еще работает, как я могу вызвать stopForeground, когда нажата кнопка отмены? – IrApp