gpt4 book ai didi

java - 滑动关闭前台服务通知

转载 作者:行者123 更新时间:2023-12-04 20:13:11 25 4
gpt4 key购买 nike

我正在尝试忽略来自前台服务的通知,但还没有找到任何解决方案。我没有使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com