mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 06:10:31 +05:30
commit
8e13e563ab
@ -11,6 +11,7 @@ import android.os.Environment
|
||||
import android.os.IBinder
|
||||
import android.widget.Toast
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.util.DownloadHelper
|
||||
import java.io.File
|
||||
|
||||
class UpdateService : Service() {
|
||||
@ -28,9 +29,7 @@ class UpdateService : Service() {
|
||||
}
|
||||
|
||||
private fun downloadApk(downloadUrl: String) {
|
||||
val dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
|
||||
// val dir = applicationContext.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)
|
||||
file = File(dir, "release.apk")
|
||||
file = File(getDownloadDirectory(), "release.apk")
|
||||
|
||||
val request: DownloadManager.Request =
|
||||
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() {
|
||||
unregisterReceiver(onDownloadComplete)
|
||||
super.onDestroy()
|
||||
|
@ -11,7 +11,7 @@ object DownloadHelper {
|
||||
const val METADATA_DIR = "metadata"
|
||||
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
|
||||
|
||||
return try {
|
||||
|
Loading…
Reference in New Issue
Block a user