【问题标题】:How can i ask for multpile MIME types with ActivityResultLauncher.GetContent()?如何使用 ActivityResultLauncher.GetContent() 请求多种 MIME 类型?
【发布时间】:2021-11-20 10:31:44
【问题描述】:

我正在尝试从用户那里检索一个可以是图像或 pdf 的文件,使用

registerForActivityResult(ActivityResultContracts.GetContent()) { file: Uri ->
   ......
}.launch(<mimetypes>)

我已经从另一个问题的答案中尝试过"image/*|application/pdf",但它不起作用,有没有办法在使用 registerForActivityResult 时要求多种 MIME 类型?

【问题讨论】:

    标签: android mime-types


    【解决方案1】:

    在使用 registerForActivityResult 时有什么方法可以要求多个 MIME 类型?

    不直接使用当前版本的ActivityResultContracts.GetContent。但是,您应该能够对其进行子类化,覆盖createIntent(),并从那里自定义生成的Intent。然后,您可以尝试将 EXTRA_MIME_TYPES 添加到该 Intent 以及您想要的其他 MIME 类型的 String[]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-14
      • 1970-01-01
      • 1970-01-01
      • 2022-10-18
      • 2015-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多