Cannot get image from gallery. Want to get images from gallery and display it. I am using coil library for displaying image.
var images by remember { mutableStateOf(listOf<Uri>()) }
val galleryLauncher =
rememberLauncherForActivityResult(ActivityResultContracts.GetMultipleContents()) {
images = it
}
Column() {
Button(
onClick = {
galleryLauncher.launch("image/*")
}
) {
Text(text = "Get images")
}
LazyColumn(content = {
items(images.size){ uri ->
AsyncImage(model = uri, contentDescription = null)
}
})
}
the problem is your are using the wrong
itemsfunction in yourlazyColumn. the one you are using takes anintas a parametre and then it gives anIntto the body not auri.:you should use the other Items function from
androidx.compose.foundation.lazy.itemsand your code should something like this: