fix: clear notification when app is killed from recent tasks (#6063)

This commit is contained in:
Nur Shuvo 2024-05-26 22:26:00 +06:00 committed by GitHub
parent aa40047b4d
commit 607468216c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 34 additions and 0 deletions

View File

@ -394,6 +394,10 @@
android:exported="false"
android:foregroundServiceType="mediaPlayback" />
<service android:name=".services.OnClearFromRecentService"
android:enabled="true"
android:exported="false" />
<receiver
android:name=".receivers.NotificationReceiver"
android:enabled="true"

View File

@ -0,0 +1,28 @@
package com.github.libretube.services
import android.app.NotificationManager
import android.app.Service
import android.content.Intent
import android.os.IBinder
import androidx.core.content.getSystemService
import com.github.libretube.enums.NotificationId
class OnClearFromRecentService : Service() {
private var nManager: NotificationManager? = null
override fun onBind(p0: Intent?): IBinder? = null
override fun onStartCommand(
intent: Intent?,
flags: Int,
startId: Int,
): Int {
nManager = getSystemService<NotificationManager>()
return START_NOT_STICKY
}
override fun onTaskRemoved(rootIntent: Intent?) {
nManager?.cancel(NotificationId.PLAYER_PLAYBACK.id)
stopSelf()
}
}

View File

@ -28,6 +28,7 @@ import com.github.libretube.extensions.toMediaMetadataCompat
import com.github.libretube.helpers.ImageHelper
import com.github.libretube.helpers.PlayerHelper
import com.github.libretube.obj.PlayerNotificationData
import com.github.libretube.services.OnClearFromRecentService
import com.github.libretube.ui.activities.MainActivity
import java.util.UUID
@ -303,6 +304,7 @@ class NowPlayingNotification(
super.onIsPlayingChanged(isPlaying)
}
})
context.startService(Intent(context, OnClearFromRecentService::class.java))
}
createOrUpdateNotification()