kotlin Activity结果启动器Jetpack中的多个MIME类型组成

iyfamqjs  于 2023-08-06  发布在  Kotlin
关注(0)|答案(2)|浏览(106)

如何在jetpack compose中的activity result launcher中设置多个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?

字符串

axr492tv

axr492tv1#

您需要将MIME类型添加到Intent:

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

字符串
我不能100%确定那些MIME类型是否正确

pexxcrt2

pexxcrt22#

val documentPickerLauncher = rememberLauncherForActivityResult(
    contract = contracts,
    onResult = {
        // performing operations with selected file.
    })
val scope = rememberCoroutineScope()
scope.launch {
    // launching the file picker
    launcher.launch(arrayOf("application/pdf", "image/png"))
}

字符串

相关问题