@Composable
fun MainScreen() {
val context = LocalContext.current
var imageUri: Any? by remember { mutableStateOf(R.drawable.logo) }
val photoPicker = rememberLauncherForActivityResult(
contract = ActivityResultContracts.PickVisualMedia()
) {
if (it != null) {
Log.d("PhotoPicker", "Selected URI: $it")
imageUri = it
} else {
Log.d("PhotoPicker", "No media selected")
}
}
// val multiplePhotoPicker = rememberLauncherForActivityResult(
// contract = ActivityResultContracts.PickMultipleVisualMedia(maxItems = 2)
// ) {
//
// }
Column(
modifier = Modifier.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
AsyncImage(
modifier = Modifier
.size(250.dp)
.clickable {
photoPicker.launch(
PickVisualMediaRequest(
ActivityResultContracts.PickVisualMedia.ImageAndVideo
)
)
},
model = ImageRequest.Builder(LocalContext.current)
.data(imageUri)
.crossfade(enable = true)
.build(),
contentDescription = "Avatar Image",
contentScale = ContentScale.Crop,
)
Spacer(modifier = Modifier.height(24.dp))
Button(onClick = {
Toast.makeText(
context,
isPhotoPickerAvailable(context).toString(),
Toast.LENGTH_LONG
).show()
}) {
Text(text = "Availability")
}
}
}
0 Comments