簡體   English   中英

當應用程序從 android studio 中最近的應用程序停止時清除 exo 播放器通知

[英]Clear exo player notification when app stops from recent apps in android studio

我正在使用 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 中聲明了它。

請問有什么幫助嗎?

檢查此答案如何殺死前台服務以及應用程序和示例https://androidwave.com/foreground-service-android-example/

在 android 8 及更高版本中,您必須使用前台服務。

在清除通知后和殺死應用程序之前添加一個小延遲或創建一個通知您通知已清除的功能

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM