【发布时间】:2020-03-11 19:47:39
【问题描述】:
我正在使用 exoplayer 库开发一个用于广播流媒体的应用程序。所以,当我关闭应用程序(从最近的应用程序等)时,我想清除(删除)exoplayer 通知栏(带有播放/停止按钮)。现在,我关闭了应用程序,但通知栏仍然出现,并且不会通过向左/向右滑动来关闭。
我尝试了以下源代码但它不起作用(我尝试将源代码的行与方法分开运行但我无法解决问题)。
public class RadioService extends Service {
......
.......
......
public void onTaskRemoved(Intent rootIntent) {
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.cancel(NOTIFICATION_ID);
stopForeground(true);
notificationManager.cancelAll();
}
public void onDestroy() {
super.onDestroy();
stopForeground(true);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.cancel(NOTIFICATION_ID);
}
}
我也在 AndroidManifest.xml 中声明了它。
有什么帮助吗?
【问题讨论】:
标签: android-studio android-notifications exoplayer android-notification-bar ondestroy