[Android] Oreo: Add isForeground() utility method
Geoffrey Métais
git at videolan.org
Fri Sep 1 12:59:21 CEST 2017
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Sep 1 12:49:57 2017 +0200| [227ef2e8f75eed5c3f250600f37cf6771b48a677] | committer: Geoffrey Métais
Oreo: Add isForeground() utility method
> https://code.videolan.org/videolan/vlc-android/commit/227ef2e8f75eed5c3f250600f37cf6771b48a677
---
vlc-android/src/org/videolan/vlc/util/Util.java | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/vlc-android/src/org/videolan/vlc/util/Util.java b/vlc-android/src/org/videolan/vlc/util/Util.java
index 0254fded1..c45202c41 100644
--- a/vlc-android/src/org/videolan/vlc/util/Util.java
+++ b/vlc-android/src/org/videolan/vlc/util/Util.java
@@ -20,6 +20,7 @@
package org.videolan.vlc.util;
+import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
@@ -149,6 +150,7 @@ public class Util {
for (T newItem : items) {
for (T oldItem : dataset) {
if (newItem.equals(oldItem)) {
+ //noinspection UnusedAssignment
oldItem = newItem;
continue outer;
}
@@ -166,4 +168,17 @@ public class Util {
contentBuilder.append(album);
return contentBuilder.toString();
}
+
+ /**
+ * Starts a service in Foreground in Android 8+
+ * To be removed with AppCompat 26+
+ * @param ctx the context
+ * @param intent service intent to start
+ */
+ public static void startService(Context ctx, Intent intent) {
+ if (VLCApplication.isForeground())
+ ctx.startService(intent);
+ else
+ ctx.startForegroundService(intent);
+ }
}
More information about the Android
mailing list