Однако их URI содержимого хранится в базе данных. Изначально я хранил только Uris средства выбора контента, который выглядел так:
Код: Выделить всё
content://media/picker/0/com.android.providers.media.photopicker/media/1001290474
Код: Выделить всё
@Entity(tableName = "notes_tbl")
data class Note(
@PrimaryKey
val id: UUID = UUID.randomUUID(),
@ColumnInfo(name = "note_title")
var title: String,
@ColumnInfo(name = "note_body")
var desc: String,
@ColumnInfo(name = "note_images")
var images: List = emptyList()
)
Код: Выделить всё
val multiplePhotoPicker = rememberLauncherForActivityResult(
contract = ActivityResultContracts.PickMultipleVisualMedia(),
onResult = {
uris -> uriList.value = uris
}
)
Код: Выделить всё
fun getNote(id: String): Note {
return notesList.value.first { note -> note.id.toString() == id }
}
Код: Выделить всё
val saveImageToInternalStorage: (Context, Uri) -> String = {
context: Context, uri: Uri ->
val fileName = UUID.randomUUID().toString()+".jpg"
val inputStream = context.contentResolver.openInputStream(uri)
val outputStream = context.openFileOutput(fileName, Context.MODE_PRIVATE)
inputStream.use {
input ->
outputStream.use {
output ->
input?.copyTo(output)
}
}
fileName
}
Подробнее здесь: https://stackoverflow.com/questions/783 ... th-in-room