File tree Expand file tree Collapse file tree 3 files changed +11
-5
lines changed
app/src/main/java/org/shirabox/app/ui/activity
core/src/main/java/org/shirabox/core/util Expand file tree Collapse file tree 3 files changed +11
-5
lines changed Original file line number Diff line number Diff line change 11package org.shirabox.app.ui.activity.downloads
22
33import android.content.Context
4- import android.content.Intent
54import android.os.Handler
65import android.os.Looper
76import android.widget.Toast
@@ -125,7 +124,7 @@ class DownloadsViewModel @Inject constructor(@ApplicationContext context: Contex
125124 launch { db.downloadDao().deleteDownload(contentAndDownload.second) }
126125 }
127126
128- context.startService( Intent ( context, MediaDownloadsService ::class .java) )
127+ Util .startForegroundService( context, MediaDownloadsService ::class .java)
129128 }
130129 }
131130
Original file line number Diff line number Diff line change 11package org.shirabox.app.ui.activity.resource
22
33import android.content.Context
4- import android.content.Intent
54import android.widget.Toast
65import androidx.compose.runtime.mutableLongStateOf
76import androidx.compose.runtime.mutableStateListOf
@@ -252,7 +251,7 @@ class ResourceViewModel @Inject constructor(@ApplicationContext context: Context
252251 )
253252 }
254253
255- context.startService( Intent ( context, MediaDownloadsService ::class .java) )
254+ Util .startForegroundService( context, MediaDownloadsService ::class .java)
256255 DownloadsServiceHelper .enqueue(db = db, tasks)
257256 }
258257 }
Original file line number Diff line number Diff line change @@ -177,7 +177,7 @@ class Util {
177177 }
178178
179179 packageInfo.versionName
180- } catch (e : Exception ) {
180+ } catch (_ : Exception ) {
181181 null
182182 }
183183 }
@@ -206,5 +206,13 @@ class Util {
206206 }
207207 return false
208208 }
209+
210+ fun startForegroundService (context : Context , clazz : Class <* >) {
211+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
212+ context.startForegroundService(Intent (context, clazz))
213+ } else {
214+ context.startService(Intent (context, clazz))
215+ }
216+ }
209217 }
210218}
You can’t perform that action at this time.
0 commit comments