Issue
After passing through the system file manager, the file manager I made is able to return a file when asked (say, by K9 email client) through ACTION_GET_CONTENT with this:
Uri uri = SearchOut.getUriFromFile(this, context.getPackageName(), file);
Intent intent = new Intent();
intent.setDataAndType(uri, getContentResolver().getType(uri));
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
setResult(Activity.RESULT_OK, intent);
K9 gets the file normally.
My file manager is also able to share multiple files with this:
ArrayList<Uri> urilist = ...
Intent shareIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, urilist);
shareIntent.setType("application/octet-stream");
context.startActivity(Intent.createChooser(shareIntent, "Sharing files..."));
Then I can open K9 and loads all the files.
So how do I return SEVERAL files to K9 when they are requested through ACTION_GET_CONTENT?
As I wrote above, I know how to send several files with K9, or return 1 file when K9 asks, but I don't know how to return several files when K9 asks. The system file manager does return several files and K9 loads all of them happily.
Solution
I solved the problem using ClipData
(needs API >= 16). Not sure if it is the best way to build the ClipData, though:
ClipData clipData = null;
for (Uri u : getSelectedFilesToArrayOfUri()) {
if (clipData == null)
clipData = ClipData.newRawUri(null, u);
else
clipData.addItem(new ClipData.Item(u));
}
intent.setClipData(clipData);
intent.setType("application/octet-stream");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
setResult(Activity.RESULT_OK, intent);
Answered By - Luis A. Florit
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.