Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android studio 在android studio中,当应用程序从最近的应用程序停止时,清除exo player通知_Android Studio_Android Notifications_Exoplayer_Android Notification Bar_Ondestroy - Fatal编程技术网

Android studio 在android studio中,当应用程序从最近的应用程序停止时,清除exo player通知

Android studio 在android studio中,当应用程序从最近的应用程序停止时,清除exo player通知,android-studio,android-notifications,exoplayer,android-notification-bar,ondestroy,Android Studio,Android Notifications,Exoplayer,Android Notification Bar,Ondestroy,我正在使用exoplayer库开发一个广播流应用程序。因此,我想在关闭应用程序(从最近的应用程序e.t.c)时清除(删除)exoplayer通知栏(带有播放/停止按钮)。现在,我关闭了应用程序,但通知栏仍会出现,并且不会通过左/右滑动关闭 我尝试了下面的源代码,但不起作用(我尝试将源代码行与方法分开运行,但无法解决问题) 我也在AndroidManifest.xml中声明了它 有什么帮助吗?请检查此答案和示例 在android 8及以上版本中,您必须使用前台服务。在清除通知后,在关闭应用程序或

我正在使用exoplayer库开发一个广播流应用程序。因此,我想在关闭应用程序(从最近的应用程序e.t.c)时清除(删除)exoplayer通知栏(带有播放/停止按钮)。现在,我关闭了应用程序,但通知栏仍会出现,并且不会通过左/右滑动关闭

我尝试了下面的源代码,但不起作用(我尝试将源代码行与方法分开运行,但无法解决问题)

我也在AndroidManifest.xml中声明了它

有什么帮助吗?

请检查此答案和示例


在android 8及以上版本中,您必须使用前台服务。

在清除通知后,在关闭应用程序或创建通知您清除通知的功能之前,添加一个小延迟

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);

    }
}