Browse Source

Fix

Signed-off-by: Mario Danic <mario@lovelyhq.com>
Mario Danic 7 years ago
parent
commit
4880e783bf

+ 10 - 2
src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java

@@ -428,7 +428,11 @@ public class SynchronizeFolderOperation extends SyncOperation {
                 Intent i = new Intent(mContext, FileDownloader.class);
                 i.putExtra(FileDownloader.EXTRA_ACCOUNT, mAccount);
                 i.putExtra(FileDownloader.EXTRA_FILE, file);
-                mContext.startService(i);
+                if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
+                    mContext.startForegroundService(i);
+                } else {
+                    mContext.startService(i);
+                }
             }
         }
     }
@@ -507,7 +511,11 @@ public class SynchronizeFolderOperation extends SyncOperation {
         intent.setAction(OperationsService.ACTION_SYNC_FOLDER);
         intent.putExtra(OperationsService.EXTRA_ACCOUNT, mAccount);
         intent.putExtra(OperationsService.EXTRA_REMOTE_PATH, path);
-        mContext.startService(intent);
+        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
+            mContext.startForegroundService(intent);
+        } else {
+            mContext.startService(intent);
+        }
     }
 
     public String getRemotePath() {

+ 5 - 1
src/main/java/com/owncloud/android/providers/DocumentsStorageProvider.java

@@ -136,7 +136,11 @@ public class DocumentsStorageProvider extends DocumentsProvider {
             Intent i = new Intent(getContext(), FileDownloader.class);
             i.putExtra(FileDownloader.EXTRA_ACCOUNT, account);
             i.putExtra(FileDownloader.EXTRA_FILE, file);
-            context.startService(i);
+            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
+                context.startForegroundService(i);
+            } else {
+                context.startService(i);
+            }
 
             do {
                 if (!waitOrGetCancelled(cancellationSignal)) {