insert created nomedia files into MediaStore manually
This commit is contained in:
parent
736416c26c
commit
a4c590ddd3
1 changed files with 18 additions and 4 deletions
|
@ -3,6 +3,7 @@ package com.simplemobiletools.gallery.pro.extensions
|
|||
import android.annotation.TargetApi
|
||||
import android.app.Activity
|
||||
import android.content.ContentProviderOperation
|
||||
import android.content.ContentValues
|
||||
import android.content.Intent
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
|
@ -13,6 +14,7 @@ import android.media.ExifInterface
|
|||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.provider.MediaStore
|
||||
import android.provider.MediaStore.Files
|
||||
import android.provider.MediaStore.Images
|
||||
import android.util.DisplayMetrics
|
||||
import android.view.View
|
||||
|
@ -147,9 +149,8 @@ fun BaseSimpleActivity.addNoMedia(path: String, callback: () -> Unit) {
|
|||
val fileDocument = getDocumentFile(path)
|
||||
if (fileDocument?.exists() == true && fileDocument.isDirectory) {
|
||||
fileDocument.createFile("", NOMEDIA)
|
||||
applicationContext.scanPathRecursively(file.absolutePath) {
|
||||
callback()
|
||||
}
|
||||
addNoMediaIntoMediaStore(file.absolutePath)
|
||||
callback()
|
||||
} else {
|
||||
toast(R.string.unknown_error_occurred)
|
||||
callback()
|
||||
|
@ -158,7 +159,7 @@ fun BaseSimpleActivity.addNoMedia(path: String, callback: () -> Unit) {
|
|||
} else {
|
||||
try {
|
||||
if (file.createNewFile()) {
|
||||
rescanFolderMedia(file.absolutePath)
|
||||
addNoMediaIntoMediaStore(file.absolutePath)
|
||||
} else {
|
||||
toast(R.string.unknown_error_occurred)
|
||||
}
|
||||
|
@ -169,6 +170,19 @@ fun BaseSimpleActivity.addNoMedia(path: String, callback: () -> Unit) {
|
|||
}
|
||||
}
|
||||
|
||||
fun BaseSimpleActivity.addNoMediaIntoMediaStore(path: String) {
|
||||
try {
|
||||
val content = ContentValues().apply {
|
||||
put(Files.FileColumns.TITLE, NOMEDIA)
|
||||
put(Files.FileColumns.DATA, path)
|
||||
put(Files.FileColumns.MEDIA_TYPE, Files.FileColumns.MEDIA_TYPE_NONE)
|
||||
}
|
||||
contentResolver.insert(Files.getContentUri("external"), content)
|
||||
} catch (e: Exception) {
|
||||
showErrorToast(e)
|
||||
}
|
||||
}
|
||||
|
||||
fun BaseSimpleActivity.removeNoMedia(path: String, callback: (() -> Unit)? = null) {
|
||||
val file = File(path, NOMEDIA)
|
||||
if (!getDoesFilePathExist(file.absolutePath)) {
|
||||
|
|
Loading…
Reference in a new issue