Hope you are doing well.
This question is about API level 29 or above. I just want to create folder like WhatsApp creating it's own folder ad store my files under it.
I've tried Media Store APIs so far, but it gives me access only Audio, Image, Video, Audio, Files (Document, Download). So how can I create my own app folder ?
I've got success to store my data into Document -> MY_APP_FOLDER but it gives me something weird path of it /storage/emulated/0/Documents/App Name/mydata.zip/mydata.zip.
My Code is :
val folderValue = ContentValues()
folderValue.put(MediaStore.MediaColumns.DISPLAY_NAME, "mydata")
folderValue.put(MediaStore.MediaColumns.MIME_TYPE, "application/zip")
folderValue.put(MediaStore.MediaColumns.RELATIVE_PATH, "${Environment.DIRECTORY_DOCUMENTS}/App Name/")
val uri: Uri? = context.contentResolver?.insert(
MediaStore.Files.getContentUri("external"), folderValue
)
val outputStream: OutputStream? = context.contentResolver?.openOutputStream(uri!!)
outputStream?.write(fileBytes)
outputStream?.close()
After creating successfully this when I tried to get real path from uri it return me /storage/emulated/0/Documents/App Name/mydata.zip/mydata.zip.
Why there are 2 times "mydata.zip" in my path ??
Please help me out from this.!
Thank you in advanced.