diff --git a/app/src/main/java/io/legado/app/service/DownloadService.kt b/app/src/main/java/io/legado/app/service/DownloadService.kt index 3d2e8e6c2..013e6c630 100644 --- a/app/src/main/java/io/legado/app/service/DownloadService.kt +++ b/app/src/main/java/io/legado/app/service/DownloadService.kt @@ -6,15 +6,13 @@ import android.content.Context import android.content.Intent import android.content.IntentFilter import android.net.Uri -import android.os.Build import android.os.Environment import androidx.core.app.NotificationCompat import io.legado.app.R import io.legado.app.base.BaseService import io.legado.app.constant.AppConst import io.legado.app.constant.IntentAction -import io.legado.app.utils.IntentType -import io.legado.app.utils.msg +import io.legado.app.utils.openFileUri import io.legado.app.utils.servicePendingIntent import io.legado.app.utils.toastOnUi import kotlinx.coroutines.Job @@ -172,20 +170,7 @@ class DownloadService : BaseService() { private fun openDownload(downloadId: Long) { downloadManager.getUriForDownloadedFile(downloadId)?.let { uri -> - //调用系统安装apk - val intent = Intent() - intent.action = Intent.ACTION_VIEW - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - //7.0版本以上 - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) - } - intent.setDataAndType(uri, IntentType.from(uri)) - try { - startActivity(intent) - } catch (e: Exception) { - toastOnUi(e.msg) - } + openFileUri(uri) } } diff --git a/app/src/main/java/io/legado/app/ui/book/local/ImportBookAdapter.kt b/app/src/main/java/io/legado/app/ui/book/local/ImportBookAdapter.kt index 86896c35b..75364291d 100644 --- a/app/src/main/java/io/legado/app/ui/book/local/ImportBookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/local/ImportBookAdapter.kt @@ -1,5 +1,6 @@ package io.legado.app.ui.book.local +import android.annotation.SuppressLint import android.content.Context import android.net.Uri import android.view.ViewGroup @@ -79,6 +80,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) : } } + @SuppressLint("NotifyDataSetChanged") fun upBookHas(bookUrls: List) { bookFileNames.clear() bookUrls.forEach { @@ -99,6 +101,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) : callBack.upCountView() } + @SuppressLint("NotifyDataSetChanged") fun selectAll(selectAll: Boolean) { if (selectAll) { getItems().forEach { diff --git a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt index 417f43b28..97cff9d38 100644 --- a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt @@ -15,6 +15,7 @@ import android.graphics.Bitmap import android.graphics.drawable.Drawable import android.net.Uri import android.os.BatteryManager +import android.os.Build import android.provider.Settings import android.widget.Toast import androidx.annotation.ColorRes @@ -292,6 +293,22 @@ fun Context.openUrl(uri: Uri) { } } +fun Context.openFileUri(uri: Uri) { + val intent = Intent() + intent.action = Intent.ACTION_VIEW + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + //7.0版本以上 + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + } + intent.setDataAndType(uri, IntentType.from(uri)) + try { + startActivity(intent) + } catch (e: Exception) { + toastOnUi(e.msg) + } +} + val Context.channel: String get() { try {