Merge pull request #1918 from Bnyro/master

fix updater issues
This commit is contained in:
Bnyro 2022-11-19 16:25:42 +01:00 committed by GitHub
commit 8e13e563ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View File

@ -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()

View File

@ -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 {