Fix: delete files from MediaStore when removed from app
This commit is contained in:
parent
0e5d50d111
commit
51351c2c82
1 changed files with 11 additions and 0 deletions
|
|
@ -10,6 +10,7 @@ import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
import android.provider.DocumentsContract
|
import android.provider.DocumentsContract
|
||||||
|
import android.provider.MediaStore
|
||||||
import android.util.DisplayMetrics
|
import android.util.DisplayMetrics
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
|
@ -63,9 +64,19 @@ object FileUtil {
|
||||||
if (!File(path).delete()){
|
if (!File(path).delete()){
|
||||||
DocumentFile.fromSingleUri(App.instance, Uri.parse(path))?.delete()
|
DocumentFile.fromSingleUri(App.instance, Uri.parse(path))?.delete()
|
||||||
}
|
}
|
||||||
|
deleteFileFromMediaStore(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun deleteFileFromMediaStore(path: String) {
|
||||||
|
val contentResolver = App.instance.contentResolver
|
||||||
|
val file = File(path)
|
||||||
|
val uri = MediaStore.Files.getContentUri("external")
|
||||||
|
val selection = MediaStore.MediaColumns.DATA + " =?"
|
||||||
|
val selectionArgs = arrayOf(file.absolutePath)
|
||||||
|
contentResolver.delete(uri, selection, selectionArgs)
|
||||||
|
}
|
||||||
|
|
||||||
fun exists(path: String) : Boolean {
|
fun exists(path: String) : Boolean {
|
||||||
val file = File(path)
|
val file = File(path)
|
||||||
if (path.isEmpty()) return false
|
if (path.isEmpty()) return false
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue