[Android] Force mediaparsingservice foreground on start
Geoffrey Métais
git at videolan.org
Thu Jun 28 16:57:03 CEST 2018
vlc-android | branch: 3.0.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Jun 28 16:54:32 2018 +0200| [73e27544c41d222ef73b01eab151132e0fce0d90] | committer: Geoffrey Métais
Force mediaparsingservice foreground on start
For Oreo+ devices
> https://code.videolan.org/videolan/vlc-android/commit/73e27544c41d222ef73b01eab151132e0fce0d90
---
.../src/org/videolan/vlc/MediaParsingService.java | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/MediaParsingService.java b/vlc-android/src/org/videolan/vlc/MediaParsingService.java
index de6dcc891..9cb24dd36 100644
--- a/vlc-android/src/org/videolan/vlc/MediaParsingService.java
+++ b/vlc-android/src/org/videolan/vlc/MediaParsingService.java
@@ -110,13 +110,13 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
exitCommand();
return START_NOT_STICKY;
}
- synchronized (MediaParsingService.this) {
- // Set 1s delay before displaying scan icon
- // Except for Android 8+ which expects startForeground immediately
- if (mLastNotificationTime <= 0L)
+ if (mLastNotificationTime == 0L && AndroidUtil.isOOrLater) forceForeground();
+ if (mLastNotificationTime <= 0L) {
+ synchronized (MediaParsingService.this) {
+ // Set 1s delay before displaying scan icon
+ // Except for Android 8+ which expects startForeground immediately
mLastNotificationTime = AndroidUtil.isOOrLater ? 0L : System.currentTimeMillis();
- if (AndroidUtil.isOOrLater)
- showNotification();
+ }
}
switch (intent.getAction()) {
case Constants.ACTION_INIT:
@@ -142,6 +142,11 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
return START_NOT_STICKY;
}
+ private void forceForeground() {
+ final Notification notification = NotificationHelper.createScanNotification(this, getString(R.string.loading_medialibrary), false, mScanPaused);
+ startForeground(43, notification);
+ }
+
private void discoverStorage(final String path) {
if (BuildConfig.DEBUG) Log.d(TAG, "discoverStorage: "+path);
if (TextUtils.isEmpty(path)) {
More information about the Android
mailing list