[Android] Set medialibrary service foreground on start

Geoffrey Métais git at videolan.org
Thu Jun 28 15:15:43 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Jun 28 14:37:57 2018 +0200| [b8e7a1a446cc3d463cdbc56192523610e02e79be] | committer: Geoffrey Métais

Set medialibrary service foreground on start

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

 vlc-android/src/org/videolan/vlc/MediaParsingService.kt | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/MediaParsingService.kt b/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
index 2d8c0ba35..e1442f687 100644
--- a/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
+++ b/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
@@ -125,9 +125,8 @@ class MediaParsingService : Service(), DevicesDiscoveryCb {
         synchronized(this at MediaParsingService) {
             // Set 1s delay before displaying scan icon
             // Except for Android 8+ which expects startForeground immediately
-            if (lastNotificationTime <= 0L)
-                lastNotificationTime = if (AndroidUtil.isOOrLater) 0L else System.currentTimeMillis()
-            if (AndroidUtil.isOOrLater) showNotification()
+            if (lastNotificationTime <= 0L) System.currentTimeMillis()
+            if (AndroidUtil.isOOrLater) forceForeground()
         }
         when (intent.action) {
             Constants.ACTION_INIT -> {
@@ -148,6 +147,12 @@ class MediaParsingService : Service(), DevicesDiscoveryCb {
         return Service.START_NOT_STICKY
     }
 
+    private fun forceForeground() {
+        val ctx = this at MediaParsingService
+        val notification = NotificationHelper.createScanNotification(ctx, getString(R.string.loading_medialibrary), false, mScanPaused)
+        startForeground(43, notification)
+    }
+
     private fun discoverStorage(path: String) {
         if (BuildConfig.DEBUG) Log.d(TAG, "discoverStorage: $path")
         if (TextUtils.isEmpty(path)) {



More information about the Android mailing list