[Android] Services: Create notification channels sooner

Geoffrey Métais git at videolan.org
Fri Nov 15 11:22:43 CET 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Nov 14 13:31:03 2019 +0100| [833ae8b7051203a402d0011b78f3ecdd3ecf13c0] | committer: Geoffrey Métais

Services: Create notification channels sooner

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

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

diff --git a/vlc-android/src/org/videolan/vlc/MediaParsingService.kt b/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
index 7daac8a54..826fffe61 100644
--- a/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
+++ b/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
@@ -121,8 +121,10 @@ class MediaParsingService : Service(), DevicesDiscoveryCb, CoroutineScope, Lifec
         return super.getApplicationContext().getContextWithLocale()
     }
 
+    @TargetApi(Build.VERSION_CODES.O)
     @SuppressLint("WakelockTimeout")
     override fun onCreate() {
+        if (AndroidUtil.isOOrLater) NotificationHelper.createNotificationChannels(applicationContext)
         dispatcher.onServicePreSuperOnCreate()
         super.onCreate()
         localBroadcastManager = LocalBroadcastManager.getInstance(this)
@@ -182,7 +184,6 @@ class MediaParsingService : Service(), DevicesDiscoveryCb, CoroutineScope, Lifec
     @TargetApi(Build.VERSION_CODES.O)
     private fun forceForeground() {
         val notification = NotificationHelper.createScanNotification(applicationContext, getString(R.string.loading_medialibrary), 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 43d0bebda..2a32bb283 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.kt
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.kt
@@ -85,7 +85,7 @@ class PlaybackService : MediaBrowserServiceCompat(), CoroutineScope, LifecycleOw
         get() = playlistManager.player.mediaplayer
     private lateinit var keyguardManager: KeyguardManager
     internal lateinit var settings: SharedPreferences
-    private val mBinder = LocalBinder()
+    private val binder = LocalBinder()
     internal lateinit var medialibrary: AbstractMedialibrary
 
     private val callbacks = mutableListOf<Callback>()
@@ -453,6 +453,7 @@ class PlaybackService : MediaBrowserServiceCompat(), CoroutineScope, LifecycleOw
     }
 
     override fun onCreate() {
+        if (AndroidUtil.isOOrLater) NotificationHelper.createNotificationChannels(applicationContext)
         dispatcher.onServicePreSuperOnCreate()
         super.onCreate()
         settings = Settings.getInstance(this)
@@ -555,7 +556,7 @@ class PlaybackService : MediaBrowserServiceCompat(), CoroutineScope, LifecycleOw
 
     override fun onBind(intent: Intent): IBinder? {
         dispatcher.onServicePreSuperOnBind()
-        return if (MediaBrowserServiceCompat.SERVICE_INTERFACE == intent.action) super.onBind(intent) else mBinder
+        return if (MediaBrowserServiceCompat.SERVICE_INTERFACE == intent.action) super.onBind(intent) else binder
     }
 
     val vout: IVLCVout?
@@ -566,7 +567,6 @@ class PlaybackService : MediaBrowserServiceCompat(), CoroutineScope, LifecycleOw
     @TargetApi(Build.VERSION_CODES.O)
     private fun forceForeground() {
         val ctx = this at PlaybackService
-        NotificationHelper.createNotificationChannels(ctx.applicationContext)
         val stopped = PlayerController.playbackState == PlaybackStateCompat.STATE_STOPPED
         val notification = if (this::notification.isInitialized && !stopped) notification
         else NotificationHelper.createPlaybackNotification(ctx, false,



More information about the Android mailing list