我正在尝试关闭前台服务的通知,但是还没有找到任何解决方案。我没有使用
我的NotificationCompat.Builder是:
即使我设置了`setOnGoing(false);`,它仍然不起作用。我遵循了这个线程的解决方案:从前台服务取消可取消通知。这是官方文件中的新`NotificationCompat.Builder`:
我想知道是否有解决我的问题的方案。谢谢。
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(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();
我想知道是否有解决我的问题的方案。谢谢。