gpt4 book ai didi

android - 如何在撰写中使用 Intent 启动文件选择器

转载 作者:行者123 更新时间:2023-12-04 23:51:59 26 4
gpt4 key购买 nike

我正在尝试在单击按钮时启动文件选择器(可组合功能)。无法使用 startActivityForResult() .

@Composable
fun SelectScreen() {

Button(onClick = {
val intent = Intent(Intent.ACTION_GET_CONTENT)
startActivity(intent)
}
) {
Text("BUTTON")
}
}

最佳答案

这是我的建议:

val pickPictureLauncher = rememberLauncherForActivityResult(
ActivityResultContracts.GetContent()
) { imageUri ->
if (imageUri != null) {
// Update the state with the Uri
}
}

// In your button's click
pickPictureLauncher.launch("image/*")
并在显示图像的可组合中,您可以执行以下操作
val image = remember {
// Make sure to resize and compress
// the image to avoid display a big bitmap
ImageUtils.imageFromUri(imageUi)
}
Image(
image,
contentDescription = null
)

关于android - 如何在撰写中使用 Intent 启动文件选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68768236/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com