我正在尝试忽略来自前台服务的通知,但还没有找到任何解决方案。我没有使用 notificationManager.notify(...)
但是 startForeground(...)
反而。
我的 NotificationCompat.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(假); 它仍然没有工作。我遵循了这个线程解决方案:Make a notification from a foreground service cancelable once the service is not in foreground anymore
这是新的 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();
我想知道是否有任何解决方案可以解决我的问题。谢谢
最佳答案
您可以通过滑动关闭通知;
stopForeground(false);
并完全驳回通知;
stopForeground(true);
关于java - 滑动关闭前台服务通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49511119/