mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 08:20:32 +05:30
fix: clear notification when app is killed from recent tasks (#6063)
This commit is contained in:
parent
aa40047b4d
commit
607468216c
@ -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"
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user