Deepak Gahlot
02/26/2021, 3:00 PM@Preview
@Composable
fun AttachmentComponent() {
var fileName = remember { mutableStateOf(ArrayList<String>()) }
var array = arrayOf("application/pdf")
var files = ArrayList<String>()
var fileAttached = remember { mutableStateOf(false) }
Column {
val registerTakeFile = registerForActivityResult(
ActivityResultContracts.OpenMultipleDocuments()
) {
for (i in 0 until it.size) {
var uri = it.get(i)
files.add(uri.path!!)
}
fileName.value = files
}
Text(
text = "Attachment",
color = colorResource(id = R.color.gray1)
)
if (fileAttached.value) {
FileAttached(item = fileName.value)
}
OutlinedButton(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
colors = ButtonDefaults.outlinedButtonColors(
contentColor = colorResource(id = R.color.blue1)
),
onClick = {
registerTakeFile.launch(array)
fileAttached.value = true
}
) {
Icon(painterResource(id = R.drawable.ico_attach), contentDescription = "attach")
Text(
fontSize = 14.sp,
text = "Add Files",
)
}
}
}
@Composable
fun FileAttached(item: ArrayList<String>) {
Column {
item.forEach {
Row {
Text(
text = it,
color = colorResource(id = R.color.black)
)
}
}
}
}
Ian Lake
02/26/2021, 3:06 PMDeepak Gahlot
02/26/2021, 3:07 PMCan only use lower 16 bits for requestCode
, how do i set the requestCodeIan Lake
03/15/2021, 1:30 PM