skwalking
11/21/2021, 7:05 AM@Composable
fun GetContentExample() {
val context = LocalContext.current
var directoryUri by remember { mutableStateOf<Uri?>(null) }
//val imageUri = mutableListOf<Uri?>()
//val cR = context.contentResolver
val launcher =
rememberLauncherForActivityResult(ActivityResultContracts.OpenDocumentTree()) { uri: Uri? ->
directoryUri = uri
}
Column(modifier = Modifier.fillMaxSize()) {
Button(onClick = { launcher.launch(directoryUri) }) {
Text(text = "Load Image")
}
val documentFile = directoryUri?.let { DocumentFile.fromTreeUri(context, it) }
val files = documentFile?.listFiles()
val pathList = mutableListOf<DocumentFile>()
files?.forEach { file ->
if (file.type == "image/jpeg") {
pathList.add(file)
}
}
LazyColumn(modifier = Modifier.fillMaxSize()) {
items(items = pathList) { path ->
Text(text = path.uri.toString())
Image(
painter = rememberImagePainter(path.uri),
contentDescription = "My Image"
)
Spacer(modifier = Modifier.height(20.dp))
}
}
}
}
Help Text appearing but not the images.
Here I'm first taking access to pictures folder then wanna show it on LazyColumn...
It'll be good if you provide source I can read to know how to display, copy images from one folder to another 🙂Colin White
11/21/2021, 9:01 AMrememberImagePainter(path.uri) { size(OriginalSize) }
should work around the issue, but keep an eye on that Github thread as there’s better solution coming soon.Zach Klippenstein (he/him) [MOD]
11/22/2021, 4:02 PM