Added option to run service in foreground right away

This commit is contained in:
Viktor De Pasquale 2019-07-10 19:33:44 +02:00 committed by John Wu
parent 6a0f6ab319
commit 22e73644f9

View File

@ -5,6 +5,7 @@ import android.annotation.SuppressLint
import android.app.PendingIntent import android.app.PendingIntent
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Build
import androidx.annotation.RequiresPermission import androidx.annotation.RequiresPermission
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import com.topjohnwu.magisk.ClassMap import com.topjohnwu.magisk.ClassMap
@ -85,10 +86,17 @@ open class CompoundDownloadService : SubstrateDownloadService() {
companion object { companion object {
@RequiresPermission(allOf = [Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE]) @RequiresPermission(allOf = [Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE])
fun download(context: Context, subject: DownloadSubject) = fun download(context: Context, subject: DownloadSubject) {
Intent(context, ClassMap[CompoundDownloadService::class.java]) Intent(context, ClassMap[CompoundDownloadService::class.java])
.putExtra(ARG_URL, subject) .putExtra(ARG_URL, subject)
.let { context.startService(it); Unit } .let {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(it)
} else {
context.startService(it)
}
}
}
} }