mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
commit
8e13e563ab
@ -11,6 +11,7 @@ import android.os.Environment
|
|||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
|
import com.github.libretube.util.DownloadHelper
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class UpdateService : Service() {
|
class UpdateService : Service() {
|
||||||
@ -28,9 +29,7 @@ class UpdateService : Service() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun downloadApk(downloadUrl: String) {
|
private fun downloadApk(downloadUrl: String) {
|
||||||
val dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
|
file = File(getDownloadDirectory(), "release.apk")
|
||||||
// val dir = applicationContext.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)
|
|
||||||
file = File(dir, "release.apk")
|
|
||||||
|
|
||||||
val request: DownloadManager.Request =
|
val request: DownloadManager.Request =
|
||||||
DownloadManager.Request(Uri.parse(downloadUrl))
|
DownloadManager.Request(Uri.parse(downloadUrl))
|
||||||
@ -80,6 +79,12 @@ class UpdateService : Service() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getDownloadDirectory(): File {
|
||||||
|
val downloadsDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
|
||||||
|
if (!downloadsDir.canWrite()) return DownloadHelper.getOfflineStorageDir(this)
|
||||||
|
return downloadsDir
|
||||||
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
unregisterReceiver(onDownloadComplete)
|
unregisterReceiver(onDownloadComplete)
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
|
@ -11,7 +11,7 @@ object DownloadHelper {
|
|||||||
const val METADATA_DIR = "metadata"
|
const val METADATA_DIR = "metadata"
|
||||||
const val THUMBNAIL_DIR = "thumbnail"
|
const val THUMBNAIL_DIR = "thumbnail"
|
||||||
|
|
||||||
private fun getOfflineStorageDir(context: Context): File {
|
fun getOfflineStorageDir(context: Context): File {
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return context.filesDir
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return context.filesDir
|
||||||
|
|
||||||
return try {
|
return try {
|
||||||
|
Loading…
Reference in New Issue
Block a user