Kotlin 将多个Mime类型传递给ActivityResultLauncher.launch()
我有以下代码Kotlin 将多个Mime类型传递给ActivityResultLauncher.launch(),kotlin,mime-types,onactivityresult,registerforactivityresult,Kotlin,Mime Types,Onactivityresult,Registerforactivityresult,我有以下代码 val getContent = registerForActivityResult(ActivityResultContracts.GetContent()) { uri: Uri? -> //Some code here.. } 在别的地方 getContent.launch("application/vnd.openxmlformats-officedocument.wordprocessingml.document") 我可以成功地选择
val getContent = registerForActivityResult(ActivityResultContracts.GetContent()) { uri: Uri? ->
//Some code here..
}
在别的地方
getContent.launch("application/vnd.openxmlformats-officedocument.wordprocessingml.document")
我可以成功地选择docx文件。我需要选择pdf或doc或text或docx,而不仅仅是为了能够选择一种(这里是docx)。我建议使用
OpenDocument
而不是GetContent
val documentPick =
registerForActivityResult(ActivityResultContracts.OpenDocument()) { result ->
// do something
}
在启动intent时,只需添加您想要获得的mime类型
documentPick.launch(
arrayOf(
"application/pdf",
"application/msword",
"application/ms-doc",
"application/doc",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"text/plain"
)
)
谢谢这正是我所需要的:)Android文档还没有用
registerForActivityResult
正确更新,它仍然显示startActivityForResult
:/