【问题标题】:Multiple MIME types in Activity result launcher Jetpack composeActivity 结果启动器 Jetpack 组合中的多种 MIME 类型
【发布时间】:2022-08-18 15:30:36
【问题描述】:

我们如何在 jetpack compose 的活动结果启动器中设置多个 mime 类型。

val documentPickerLauncher = rememberLauncherForActivityResult(contract = contracts, 
onResult = {
          // performing operations with selected file.
        })
        val scope = rememberCoroutineScope()
        scope.launch {
        // launching the file picker
          launcher.launch(\"*/*\")
      }

Here i can select all files in the storage. Instead of all files, i need to restrict this into png and pdf. How to acheive this?

    标签: android android-jetpack-compose android-jetpack jetpack


    【解决方案1】:

    您需要将 MIME 类型添加到意图:

    intent.putExtra(Intent.EXTRA_MIME_TYPES, arrayOf("image/png", "application/pdf"))
    

    我不能 100% 确定这些 MIME 类型是否正确

    【讨论】:

    • 是的,这可以与意图一起使用,但是知道如何在撰写启动器中将其应用于活动结果吗?在我提到的代码块中,我没有看到任何传递意图的选项。
    猜你喜欢
    • 1970-01-01
    • 2010-12-14
    • 1970-01-01
    • 2011-09-21
    • 2021-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多