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:
// ACTION_OPEN_DOCUMENT is the intent to choose a file via the system's file // browser. It appears that many cloud providers (DropBox, etc.) don't // support ACTION_OPEN_DOCUMENT, and instead we must use ACTION_GET_CONTENT // in order for them to show up in the file picker. Intent intent = new Intent(Intent.ACTION_GET_CONTENT); // Filter to only show results that can be "opened", such as a // file (as opposed to a list of contacts or timezones) intent.addCategory(Intent.CATEGORY_OPENABLE); // Use the media type they selected, 'mediaTypes' is a dropdown that allows multiple types // to be selected: ArrayList<String> l = new ArrayList<String>(); l.add(mediaTypes.getSelectedItem().toString().toLowerCase() + "/*"); String mimeTypes = new String[mediaTypes.getCount()]; intent.putExtra(Intent.EXTRA_MIME_TYPES,l.toArray(mimeTypes)); intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); Log.d(TAG,"Getting media types of: " + l.toString()); intent.setType( "*/*"); startActivityForResult(intent, GET_PATHS_CODE);
I have created a custom documents provider that allows access to local (external or internal) storage, as well as network storage for a number of providers( DropBox, etc.) that have APIs for access but have not yet built their own SAF implementation.
Question - how can my provider know what the user has requested in that intent that was used to select the file picker? I want it to understand the requested type (i.e. “video/, "image/”), then filter the file returns in a variety of ways that are also controlled by a settings dialog (i.e. “help me understand that when you say ‘image’, you mean files whose extension ends with …”).
Basically I need to know how to get that intent.putExtra data from within my DocumentsProvider class…