diff options
author | Scott Jackson <daneren2005@gmail.com> | 2018-09-01 13:51:00 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2018-09-01 13:51:00 -0700 |
commit | 0e97692e08be98d846043e283f52f2ed815dcaf6 (patch) | |
tree | 8e5469b215ad91a0ae213b7be8401741ecdb4111 /app/src/main/java/github/daneren2005/dsub/service | |
parent | 7f55a43e3d59015d03277fa77cf626c68e3bbded (diff) | |
download | dsub-0e97692e08be98d846043e283f52f2ed815dcaf6.tar.gz dsub-0e97692e08be98d846043e283f52f2ed815dcaf6.tar.bz2 dsub-0e97692e08be98d846043e283f52f2ed815dcaf6.zip |
Fixed #880: Use explicit startForegroundService for Android 8+
Diffstat (limited to 'app/src/main/java/github/daneren2005/dsub/service')
-rw-r--r-- | app/src/main/java/github/daneren2005/dsub/service/AutoMediaBrowserService.java | 2 | ||||
-rw-r--r-- | app/src/main/java/github/daneren2005/dsub/service/DownloadService.java | 12 |
2 files changed, 13 insertions, 1 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/service/AutoMediaBrowserService.java b/app/src/main/java/github/daneren2005/dsub/service/AutoMediaBrowserService.java index d4e544c6..e4edabc4 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/AutoMediaBrowserService.java +++ b/app/src/main/java/github/daneren2005/dsub/service/AutoMediaBrowserService.java @@ -524,7 +524,7 @@ public class AutoMediaBrowserService extends MediaBrowserService { public void getDownloadService() { if(DownloadService.getInstance() == null) { - startService(new Intent(this, DownloadService.class)); + DownloadService.startService(this); } waitForDownloadService(); diff --git a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java index a4ca705c..0c794c36 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java +++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java @@ -71,6 +71,7 @@ import java.util.TimerTask; import java.util.concurrent.CopyOnWriteArrayList; import android.annotation.TargetApi; +import android.app.Activity; import android.app.Service; import android.content.ComponentCallbacks2; import android.content.ComponentName; @@ -375,6 +376,17 @@ public class DownloadService extends Service { Notifications.hideDownloadingNotification(this, this, handler); } + public static void startService(Context context) { + startService(context, new Intent(context, DownloadService.class)); + } + public static void startService(Context context, Intent intent) { + PowerManager powerManager = (PowerManager) context.getSystemService(POWER_SERVICE); + if (Build.VERSION.SDK_INT < 26 || (powerManager != null && powerManager.isIgnoringBatteryOptimizations(intent.getPackage()))) { + context.startService(intent); + } else { + context.startForegroundService(intent); + } + } public static DownloadService getInstance() { return instance; } |