【发布时间】:2020-09-07 22:18:28
【问题描述】:
我的意图是让用户选择图像:
fun launchChooseFileIntent(callerFragment: BaseFragment, REQUEST_CODE: Int) {
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
addCategory(Intent.CATEGORY_OPENABLE)
type = "image/*,"
}
startActivityForResult(intent, REQUEST_CODE)
}
现在我需要用户可以选择图像和 pdf 文档。 我尝试更改 type 字符串,如
type = "image/*,application/pdf"
或喜欢
type = "image/*|application/pdf"
但它不起作用。
我也尝试添加额外的意图,例如
putExtra(Intent.EXTRA_MIME_TYPES, arrayOf("image/*", "application/pdf"))
但是应用崩溃了。
我该如何解决?
【问题讨论】:
-
"应用程序崩溃" -- 使用 Logcat 检查与您的崩溃相关的堆栈跟踪:stackoverflow.com/questions/23353173/…
标签: android android-intent mime-types