[Android] Ensure notification channels are created on start

Geoffrey Métais git at videolan.org
Mon Mar 25 11:39:38 CET 2019


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

Ensure notification channels are created on start

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

 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