浏览代码

notification workaround

Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>
parneet-guraya 9 月之前
父节点
当前提交
e75ccb328f
共有 1 个文件被更改,包括 7 次插入0 次删除
  1. 7 0
      app/src/main/java/com/nextcloud/client/media/BackgroundPlayerService.kt

+ 7 - 0
app/src/main/java/com/nextcloud/client/media/BackgroundPlayerService.kt

@@ -7,6 +7,7 @@
 
 package com.nextcloud.client.media
 
+import android.app.NotificationManager
 import android.content.BroadcastReceiver
 import android.content.Context
 import android.content.Intent
@@ -214,6 +215,12 @@ class BackgroundPlayerService : MediaSessionService(), Injectable {
             // Make sure the service is not in foreground.
             player.pause()
         }
+        // Bug in Android 14, https://github.com/androidx/media/issues/805
+        // that sometimes onTaskRemove() doesn't get called immediately
+        // eventually gets called so the service stops but the notification doesn't clear out.
+        // [WORKAROUND] So, explicitly removing the notification here.
+        val nm = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
+        nm.cancel(DefaultMediaNotificationProvider.DEFAULT_NOTIFICATION_ID)
         stopSelf()
     }