From 550b14896ee6ddc2d816535e422726649a76ac26 Mon Sep 17 00:00:00 2001 From: Boris Timofeev Date: Fri, 1 Sep 2017 18:27:07 +0300 Subject: [PATCH] support startForegroundService from Android O --- app/src/main/java/org/emunix/unipatcher/Utils.java | 9 +++++++++ .../unipatcher/ui/fragment/CreatePatchFragment.java | 2 +- .../emunix/unipatcher/ui/fragment/PatchingFragment.java | 2 +- .../unipatcher/ui/fragment/SmdFixChecksumFragment.java | 2 +- .../unipatcher/ui/fragment/SnesSmcHeaderFragment.java | 2 +- 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/emunix/unipatcher/Utils.java b/app/src/main/java/org/emunix/unipatcher/Utils.java index 92afaeb..8e11e70 100644 --- a/app/src/main/java/org/emunix/unipatcher/Utils.java +++ b/app/src/main/java/org/emunix/unipatcher/Utils.java @@ -22,6 +22,7 @@ package org.emunix.unipatcher; import android.Manifest; import android.annotation.TargetApi; import android.content.Context; +import android.content.Intent; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.os.Build; @@ -48,6 +49,14 @@ public class Utils { private static final int BUFFER_SIZE = 10240; // 10 Kb + public static void startForegroundService(Context context, Intent intent) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { + context.startService(intent); + } else { + context.startForegroundService(intent); + } + } + public static String getAppVersion(Context context) { String versionName = "N/A"; try { diff --git a/app/src/main/java/org/emunix/unipatcher/ui/fragment/CreatePatchFragment.java b/app/src/main/java/org/emunix/unipatcher/ui/fragment/CreatePatchFragment.java index b3c90e9..7eceee2 100644 --- a/app/src/main/java/org/emunix/unipatcher/ui/fragment/CreatePatchFragment.java +++ b/app/src/main/java/org/emunix/unipatcher/ui/fragment/CreatePatchFragment.java @@ -200,7 +200,7 @@ public class CreatePatchFragment extends ActionFragment implements View.OnClickL intent.putExtra("sourcePath", sourcePath); intent.putExtra("modifiedPath", modifiedPath); intent.putExtra("patchPath", patchPath); - getActivity().startService(intent); + Utils.startForegroundService(getActivity(), intent); Toast.makeText(getActivity(), R.string.toast_create_patch_started_check_notify, Toast.LENGTH_SHORT).show(); return true; diff --git a/app/src/main/java/org/emunix/unipatcher/ui/fragment/PatchingFragment.java b/app/src/main/java/org/emunix/unipatcher/ui/fragment/PatchingFragment.java index 57f2da5..3210506 100644 --- a/app/src/main/java/org/emunix/unipatcher/ui/fragment/PatchingFragment.java +++ b/app/src/main/java/org/emunix/unipatcher/ui/fragment/PatchingFragment.java @@ -217,7 +217,7 @@ public class PatchingFragment extends ActionFragment implements View.OnClickList intent.putExtra("romPath", romPath); intent.putExtra("patchPath", patchPath); intent.putExtra("outputPath", outputPath); - getActivity().startService(intent); + Utils.startForegroundService(getActivity(), intent); Toast.makeText(getActivity(), R.string.toast_patching_started_check_notify, Toast.LENGTH_SHORT).show(); return true; diff --git a/app/src/main/java/org/emunix/unipatcher/ui/fragment/SmdFixChecksumFragment.java b/app/src/main/java/org/emunix/unipatcher/ui/fragment/SmdFixChecksumFragment.java index c97a8a0..7b68bc3 100644 --- a/app/src/main/java/org/emunix/unipatcher/ui/fragment/SmdFixChecksumFragment.java +++ b/app/src/main/java/org/emunix/unipatcher/ui/fragment/SmdFixChecksumFragment.java @@ -143,7 +143,7 @@ public class SmdFixChecksumFragment extends ActionFragment implements View.OnCli Intent intent = new Intent(getActivity(), WorkerService.class); intent.putExtra("romPath", romPath); intent.putExtra("action", Action.SMD_FIX_CHECKSUM); - getActivity().startService(intent); + Utils.startForegroundService(getActivity(), intent); Toast.makeText(getActivity(), R.string.notify_smd_fix_checksum_started_check_notify, Toast.LENGTH_SHORT).show(); return true; diff --git a/app/src/main/java/org/emunix/unipatcher/ui/fragment/SnesSmcHeaderFragment.java b/app/src/main/java/org/emunix/unipatcher/ui/fragment/SnesSmcHeaderFragment.java index 8bfb6c4..45c123b 100644 --- a/app/src/main/java/org/emunix/unipatcher/ui/fragment/SnesSmcHeaderFragment.java +++ b/app/src/main/java/org/emunix/unipatcher/ui/fragment/SnesSmcHeaderFragment.java @@ -188,7 +188,7 @@ public class SnesSmcHeaderFragment extends ActionFragment implements View.OnClic intent.putExtra("action", action); intent.putExtra("romPath", romPath); intent.putExtra("headerPath", headerPath); - getActivity().startService(intent); + Utils.startForegroundService(getActivity(), intent); if (action == Action.SNES_ADD_SMC_HEADER) { Toast.makeText(getActivity(), R.string.notify_snes_add_smc_header_stared_check_noify, Toast.LENGTH_SHORT).show();