1

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!

csk
  • 188
  • 1
  • 10
  • 1
    Possible duplicate of [Android file chooser with specific file extensions](https://stackoverflow.com/questions/27407157/android-file-chooser-with-specific-file-extensions) – Salem Apr 23 '19 at 17:41
  • Thank you for your answer! I was looking for something better than interact a list of all files and then select those which have the extension that I wish... isn't there any way to add a filter like ``.setExtensionFilter(".xxx") `` ? thanks again. – csk Apr 23 '19 at 18:02

1 Answers1

2

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().

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thank you for your answer! the extension I need is ```.shp```. So, it is not so well-known. I think I will do this filter "by hand". – csk Apr 23 '19 at 19:42