2020-07-15 14:52:31 +00:00
|
|
|
package com.vanced.manager.utils
|
|
|
|
|
|
|
|
import android.app.DownloadManager
|
|
|
|
import android.content.Context
|
|
|
|
import android.net.Uri
|
|
|
|
import com.vanced.manager.R
|
|
|
|
|
|
|
|
object DownloadHelper {
|
|
|
|
|
|
|
|
fun download(url: String, dir: String, child: String, context: Context): Long {
|
|
|
|
val request = DownloadManager.Request(Uri.parse(url)).apply {
|
|
|
|
setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI)
|
|
|
|
setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE)
|
|
|
|
setTitle(context.getString(R.string.downloading_file, child))
|
2020-07-22 13:33:45 +00:00
|
|
|
setDestinationInExternalFilesDir(context, dir, child)
|
2020-07-15 14:52:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
val downloadManager = context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
|
|
|
|
return downloadManager.enqueue(request)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|