[Android] Ensure notification channels are created on start

Geoffrey Métais git at videolan.org
Thu Mar 28 14:28:57 CET 2019


vlc-android | branch: 3.1.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Mar 25 11:38:47 2019 +0100| [b1073a00493eed4275b08bbf897abea987ba76b6] | committer: Geoffrey Métais

Ensure notification channels are created on start

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

 vlc-android/src/org/videolan/vlc/MediaParsingService.kt | 4 ++++
 vlc-android/src/org/videolan/vlc/PlaybackService.kt     | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/vlc-android/src/org/videolan/vlc/MediaParsingService.kt b/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
index 908e62233..566c045c8 100644
--- a/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
+++ b/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
@@ -23,6 +23,7 @@
 package org.videolan.vlc
 
 import android.annotation.SuppressLint
+import android.annotation.TargetApi
 import android.app.Service
 import android.content.BroadcastReceiver
 import android.content.Context
@@ -30,6 +31,7 @@ import android.content.Intent
 import android.content.IntentFilter
 import android.net.Uri
 import android.os.Binder
+import android.os.Build
 import android.os.IBinder
 import android.os.PowerManager
 import android.text.TextUtils
@@ -137,8 +139,10 @@ class MediaParsingService : Service(), DevicesDiscoveryCb, CoroutineScope {
         return Service.START_NOT_STICKY
     }
 
+    @TargetApi(Build.VERSION_CODES.O)
     private fun forceForeground() {
         val notification = NotificationHelper.createScanNotification(applicationContext, getString(R.string.loading_medialibrary), false, scanPaused)
+        NotificationHelper.createNotificationChannels(applicationContext)
         startForeground(43, notification)
     }
 
diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.kt b/vlc-android/src/org/videolan/vlc/PlaybackService.kt
index f31c08a01..78d76d878 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.kt
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.kt
@@ -563,6 +563,7 @@ class PlaybackService : MediaBrowserServiceCompat(), CoroutineScope, LifecycleOw
             return playlistManager.player.getVout()
         }
 
+    @TargetApi(Build.VERSION_CODES.O)
     private fun forceForeground() {
         val ctx = this at PlaybackService
         val stopped = playlistManager.player.playbackState == PlaybackStateCompat.STATE_STOPPED
@@ -570,6 +571,7 @@ class PlaybackService : MediaBrowserServiceCompat(), CoroutineScope, LifecycleOw
         else NotificationHelper.createPlaybackNotification(ctx,false,
                 ctx.resources.getString(R.string.loading), "", "",null,
                 false, true, mediaSession.sessionToken, sessionPendingIntent)
+        NotificationHelper.createNotificationChannels(ctx.applicationContext)
         startForeground(3, notification)
         isForeground = true
         if (isVideoPlaying || AndroidDevices.showTvUi(this) || stopped) hideNotification(true)



More information about the Android mailing list