Проведите пальцем, чтобы отклонить уведомление на переднем плане службы

Я пытаюсь отклонить уведомление от службы переднего плана, но пока не могу найти решения. Я не пользуюсь notificationManager.notify(...) но startForeground(...) вместо.

Мое уведомление Compat.Builder

Intent actionCancelNotification = new Intent(MusicPlayerApp.getAppContext(), NotificationReceiver.class);
actionCancelNotification.setAction(ACTION_DISMISS_NOTIFICATION);
actionCancelNotification.putExtra(PLAYBACK_NOTIFICATION_ID, PLAYBACK_NOTI_ID);

PendingIntent dismissNotiPendingIntent = PendingIntent.getBroadcast(MusicPlayerApp.getAppContext(), 0, actionCancelNotification, 0);

    //NotificationCompat.Builder
builder.setCustomBigContentView(getRemoteView())
       .setContentTitle("SongPlayback Notification")
       .setSmallIcon(R.drawable.ic_playback_notification_icon)
       .setLargeIcon(BitmapFactory.decodeResource(MusicPlayerApp.getAppContext().getResources(), R.drawable.ic_playback_notification_icon))
       .setContentText("this is content text")
       .setSubText("sub text")
       .setDeleteIntent(dismissNotiPendingIntent)
       .build();

Даже если я setOnGoing(false); это все еще не работало. Я следовал за этим решением потока: сделать уведомление от службы переднего плана отменяемым, когда служба больше не находится на переднем плане

а это новый NotificationCompat.Builder, так как в официальном документе написано:

//NotificationCompat.Builder
builder.setCustomBigContentView(getRemoteView())
       .setContentTitle("SongPlayback Notification")
       .setSmallIcon(R.drawable.ic_playback_notification_icon)
       .setLargeIcon(BitmapFactory.decodeResource(MusicPlayerApp.getAppContext().getResources(), R.drawable.ic_playback_notification_icon))
       .setContentText("this is content text")
       .setSubText("sub text")
       //this did not work too
       .setDeleteIntent(MediaButtonReceiver.buildMediaButtonPendingIntent(MusicPlayerApp.getAppContext(), PlaybackStateCompat.ACTION_STOP)) //this d
       .build();

Интересно, есть ли решения для решения моей проблемы. Спасибо

1 ответ

Вы можете сделать уведомление отклоненным, проводя;

stopForeground(false);

И полностью отклонить уведомление;

stopForeground(true);

Этот код работал у меня точно

stopForeground(true);
Другие вопросы по тегам