How can my DocumentsProvider access the intent data used to launch the File Picker

195 Views Asked by At

I am implementing a custom DocumentsProvider. When accessing the file picker using standard Android protocol, the application can provide multiple mime types they are interested in, then request the file picker doing something like this:

        // Use the media type they selected
        intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
        intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);

        intent.setType( "*/*");
        startActivityForResult(intent, SELECT_MEDIA_CODE);

When the file picker opens, my custom document provider is shown. What I need to do in that class is be able to detect what the list of mime types was that the app stored in the 'putExtra' line above, so I can load the cursor appropriately in the document providers 'queryChildDocuments' method.

How do I get at the data in the intent that was used to launch the File Picker from within the DocumentsProvider?

1

There are 1 best solutions below

2
On

That's not possible - you should just return all of the files you have.

The mime types provided to the file picker are used for two purposes:

  • Filtering out DocumentsProviders that have set COLUMN_MIME_TYPES when there's no overlap in mime types
  • Automatically greying out documents of invalid mime types so that they cannot be selected by the user