I\'m trying to save pictures in a subfolder on Android. Here\'s a bit of my code:
File path = Environment.getExternalStoragePublicDirectory(Environment.DIREC
It's work fine for me.
MediaScannerConnection.scanFile work if there is file in directory (not directory)
private fun checkMTPFolder(f: File, context: Context) {
if (f.isDirectory) {
val newFilePath = f.absolutePath + "/tempFIle"
val newFile = File(newFilePath)
newFile.mkdir()
MediaScannerConnection.scanFile(context, arrayOf(newFilePath), null, object : MediaScannerConnection.OnScanCompletedListener {
override fun onScanCompleted(p0: String?, p1: Uri?) {
val removedFile = File(p0)
removedFile.delete()
MediaScannerConnection.scanFile(context,arrayOf(removedFile.absolutePath), null, null)
}
})
}
}