Если файлы предназначены только для потребления вашим приложением, вы можете просто записать их в кеш приложений (getExternalCacheDir
) или каталог данных (getExternalFilesDir
).
Если вы Если вы хотите сделать их доступными для других файлов, вы можете использовать среду MediaStore, как вы намекнули. Вы можете адаптировать этот пример в официальной документации к следующему:
val resolver = applicationContext.contentResolver
val imagesCollection = MediaStore.Images.Media
.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY)
val imageDetails = ContentValues().apply {
put(MediaStore.Images.Media.DISPLAY_NAME, "fancy_image.jpg")
put(MediaStore.Images.Media.IS_PENDING, 1)
}
val imageContentUri = resolver.insert(imagesCollection, imageDetails)
resolver.openFileDescriptor(imageContentUri, "w", null).use { pfd ->
int fd = pfd.getFd
// this would be your native implementation. it should `write()` to the fd or
// call `fdopen` and then `fwrite`. The `use` block will automatically call
// `close` for you.
native_writeFile(fd)
}
// Now that we're finished, release the "pending" status, and allow other apps
// to see the image
imageDetails.clear()
imageDetails.put(MediaStore.Images.Media.IS_PENDING, 0)
resolver.update(imageContentUri, imageDetails, null, null)