Search code examples
androidkotlinfilteropenfiledialog

Open file dialog with extension filter for a custom extension with kotlin


Is there any way to set a file extension filter for this intent: I want to filter files with this extension ".xxx"

val intent = Intent()
                .setType("*/*") // <- it doesn't work if I put it here (".xxx")
                .setAction(Intent.ACTION_GET_CONTENT)
            startActivityForResult(Intent.createChooser(intent, "Select a file (.xxx)"), OPEN_FILE_CODE)

Thank you!


Solution

  • Is there any way to set a file extension filter for this intent

    No, sorry.

    it doesn't work if I put it here (".xxx")

    That is because setType() takes a MIME type, not a file extension. If your file extension is common and maps to a well-known MIME type, you might try using that MIME type with setType().