Jetpack Compose: can't select csv with intent launch

23 Views Asked by At

I have been trying to read data from a csv file selected by the user. The simple code I have here works very well for pdf files, but when I click on a csv (or xls) file, the intent closes and nothing happens.

val linesCount = remember {
    mutableStateOf(0)
}
val context = LocalContext.current
val launcher = rememberLauncherForActivityResult(contract = ActivityResultContracts.GetContent()) { FileUri ->
    if (FileUri != null) {
        val inputStream: InputStream? =context.contentResolver.openInputStream(FileUri)
        val lineList = mutableListOf<String>()
        inputStream?.bufferedReader()?.forEachLine { lineList.add(it) }
        linesCount.value = lineList.size
        inputStream?.close()
    }

}
LaunchedEffect(Unit) {
    launcher.launch("*/*")
}

I've tried many alterations of the code above and I just can't get it to work.

0

There are 0 best solutions below