FilePicker icon indicating copy to clipboard operation
FilePicker copied to clipboard

[Bug]: FilePickerResultContracts.PickMedia() and PickDocumentFile()

Open pengkongkong opened this issue 8 months ago • 1 comments

Describe the bug

Using PickMedia() does not open the gallery, but behaves like PickDocumentFile()

        findViewById<Button>(R.id.btn).setOnClickListener {
            val config = DocumentFilePickerConfig(
                popUpText = "File Media",
                allowMultiple = true,
                maxFiles = 10,
                mMimeTypes = listOf("application/pdf", "image/*")
            )

            val config2 = PickMediaConfig(
                popUpIcon = R.drawable.ic_launcher_foreground,
                popUpText = "Pick Media",
                allowMultiple = true,
                maxFiles = 5,
                mPickMediaType = PickMediaType.ImageAndVideo
            )
            launcher.launch(config)
            //launcher.launch(config2)
        }
        launcher = registerForActivityResult(FilePickerResultContracts.AnyFilePicker()) { result ->
            if (result.errorMessage != null) {
                Log.e("Picker", result.errorMessage ?: "")
            } else {
                val uri = result.selectedFileUri
                val filePath = result.selectedFilePath
                Log.e("Picker--", "${uri?.path} $filePath")
            }
        }

Calling launcher.launch(config) or launcher.launch(config2) both open the document selection. Is there something I haven't set up? Or do I need to manually add some permissions? Additionally, when I set maxFiles = 1, an error occurs. How can I set it so that only one file or photo can be selected. Looking forward to your reply

Library Version

0.6.0

Steps to reproduce

No response

pengkongkong avatar Aug 22 '25 10:08 pengkongkong

pickImgLauncher.launch(
      PickMediaConfig(
          popUpText = "选择图片",
          allowMultiple = maxFiles > 1,
          maxFiles = maxFiles,
          mPickMediaType = PickMediaType.ImageOnly
      )
  )

When you want to set the maximum selection to 1, simply set single selection and do not enable multiple selection.

bymomo avatar Sep 12 '25 07:09 bymomo