[Android] Immediately set PlaybackService foreground on Oreo

Geoffrey Métais git at videolan.org
Fri Apr 27 14:55:17 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Apr 27 14:53:46 2018 +0200| [265982e3802b0943cb1768b5b789c1adce4ecc31] | committer: Geoffrey Métais

Immediately set PlaybackService foreground on Oreo

> https://code.videolan.org/videolan/vlc-android/commit/265982e3802b0943cb1768b5b789c1adce4ecc31
---

 vlc-android/src/org/videolan/vlc/PlaybackService.kt | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.kt b/vlc-android/src/org/videolan/vlc/PlaybackService.kt
index fa31d1b10..edf78943e 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.kt
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.kt
@@ -516,6 +516,7 @@ class PlaybackService : MediaBrowserServiceCompat() {
     }
 
     override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
+        if (AndroidUtil.isOOrLater && !VLCApplication.isForeground()) forceForeground()
         when (intent?.action) {
             Intent.ACTION_MEDIA_BUTTON -> {
                 if (AndroidDevices.hasTsp || AndroidDevices.hasPlayServices) MediaButtonReceiver.handleIntent(mediaSession, intent)
@@ -558,6 +559,15 @@ class PlaybackService : MediaBrowserServiceCompat() {
             return playlistManager.player.getVout()
         }
 
+    private fun forceForeground() {
+        val ctx = this at PlaybackService
+        val notification = NotificationHelper.createPlaybackNotification(ctx,false,
+                ctx.resources.getString(R.string.loading), "", "",null,
+                false, mediaSession.sessionToken, sessionPendingIntent)
+        startForeground(3, notification)
+        isForeground = true
+    }
+
     private fun sendStartSessionIdIntent() {
         val sessionId = VLCOptions.getAudiotrackSessionId()
         if (sessionId == 0) return



More information about the Android mailing list