mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-23 04:57:59 +01:00
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.annotation.TargetApi
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.ContentProviderOperation
|
import android.content.ContentProviderOperation
|
||||||
|
import android.content.ContentValues
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.graphics.BitmapFactory
|
import android.graphics.BitmapFactory
|
||||||
|
@ -13,6 +14,7 @@ import android.media.ExifInterface
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
|
import android.provider.MediaStore.Files
|
||||||
import android.provider.MediaStore.Images
|
import android.provider.MediaStore.Images
|
||||||
import android.util.DisplayMetrics
|
import android.util.DisplayMetrics
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
@ -147,9 +149,8 @@ fun BaseSimpleActivity.addNoMedia(path: String, callback: () -> Unit) {
|
||||||
val fileDocument = getDocumentFile(path)
|
val fileDocument = getDocumentFile(path)
|
||||||
if (fileDocument?.exists() == true && fileDocument.isDirectory) {
|
if (fileDocument?.exists() == true && fileDocument.isDirectory) {
|
||||||
fileDocument.createFile("", NOMEDIA)
|
fileDocument.createFile("", NOMEDIA)
|
||||||
applicationContext.scanPathRecursively(file.absolutePath) {
|
addNoMediaIntoMediaStore(file.absolutePath)
|
||||||
callback()
|
callback()
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
toast(R.string.unknown_error_occurred)
|
toast(R.string.unknown_error_occurred)
|
||||||
callback()
|
callback()
|
||||||
|
@ -158,7 +159,7 @@ fun BaseSimpleActivity.addNoMedia(path: String, callback: () -> Unit) {
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
if (file.createNewFile()) {
|
if (file.createNewFile()) {
|
||||||
rescanFolderMedia(file.absolutePath)
|
addNoMediaIntoMediaStore(file.absolutePath)
|
||||||
} else {
|
} else {
|
||||||
toast(R.string.unknown_error_occurred)
|
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) {
|
fun BaseSimpleActivity.removeNoMedia(path: String, callback: (() -> Unit)? = null) {
|
||||||
val file = File(path, NOMEDIA)
|
val file = File(path, NOMEDIA)
|
||||||
if (!getDoesFilePathExist(file.absolutePath)) {
|
if (!getDoesFilePathExist(file.absolutePath)) {
|
||||||
|
|
Loading…
Reference in a new issue