From 0b4f3f553263281333c6475cdd1a9aea414ce877 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 9 Jul 2022 17:51:58 -0400 Subject: [PATCH] Replace deprecated ACTION_MEDIA_SCANNER_SCAN_FILE intent --- .../data/notification/NotificationReceiver.kt | 3 ++- .../eu/kanade/tachiyomi/data/saver/ImageSaver.kt | 3 ++- .../eu/kanade/tachiyomi/util/storage/DiskUtil.kt | 15 ++------------- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt b/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt index 26d0a31798..71c565b7ce 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt @@ -7,6 +7,7 @@ import android.content.Intent import android.net.Uri import android.os.Build import androidx.core.content.ContextCompat +import androidx.core.net.toUri import eu.kanade.domain.chapter.interactor.GetChapter import eu.kanade.domain.chapter.interactor.UpdateChapter import eu.kanade.domain.chapter.model.Chapter @@ -203,7 +204,7 @@ class NotificationReceiver : BroadcastReceiver() { val file = File(path) file.delete() - DiskUtil.scanMedia(context, file) + DiskUtil.scanMedia(context, file.toUri()) } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/saver/ImageSaver.kt b/app/src/main/java/eu/kanade/tachiyomi/data/saver/ImageSaver.kt index 582a91103b..c8248281c0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/saver/ImageSaver.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/saver/ImageSaver.kt @@ -8,6 +8,7 @@ import android.os.Build import android.os.Environment import android.provider.MediaStore import androidx.core.content.contentValuesOf +import androidx.core.net.toUri import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.util.storage.DiskUtil import eu.kanade.tachiyomi.util.storage.cacheImageDir @@ -80,7 +81,7 @@ class ImageSaver( } } - DiskUtil.scanMedia(context, destFile) + DiskUtil.scanMedia(context, destFile.toUri()) return destFile.getUriCompat(context) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/storage/DiskUtil.kt b/app/src/main/java/eu/kanade/tachiyomi/util/storage/DiskUtil.kt index 26fa1d93a7..bcbbf25209 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/storage/DiskUtil.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/storage/DiskUtil.kt @@ -1,12 +1,11 @@ package eu.kanade.tachiyomi.util.storage import android.content.Context -import android.content.Intent +import android.media.MediaScannerConnection import android.net.Uri import android.os.Environment import android.os.StatFs import androidx.core.content.ContextCompat -import androidx.core.net.toUri import com.hippo.unifile.UniFile import eu.kanade.tachiyomi.util.lang.Hash import java.io.File @@ -74,21 +73,11 @@ object DiskUtil { } } - /** - * Scans the given file so that it can be shown in gallery apps, for example. - */ - fun scanMedia(context: Context, file: File) { - scanMedia(context, file.toUri()) - } - /** * Scans the given file so that it can be shown in gallery apps, for example. */ fun scanMedia(context: Context, uri: Uri) { - val action = Intent.ACTION_MEDIA_SCANNER_SCAN_FILE - val mediaScanIntent = Intent(action) - mediaScanIntent.data = uri - context.sendBroadcast(mediaScanIntent) + MediaScannerConnection.scanFile(context, arrayOf(uri.path), null, null) } /**