How to limit ActivityResultContract.GetContent to media (image or video)

2.1k Views Asked by At

Is there a way to make ActivityResultContract.GetContent filter only media files?

    private val selectMediaResultLauncher = registerForActivityResult(ActivityResultContracts.GetContent()) { uri: Uri? ->
    // Do something with the uri
}

Tried to use:

    selectMediaResultLauncher.launch("image/* video/*")

But no luck.

Thanks for assiting.

1

There are 1 best solutions below

0
On

You can use OpenDocument()

private val selectMediaResultLauncher = registerForActivityResult(ActivityResultContracts.OpenDocument()) { uri ->
        // Do something with the uri
    }

and:

selectMediaResultLauncher.launch(arrayOf("image/*", "video/*"))