ArrayList<Uri> uris = new ArrayList<Uri>();
for(int i = 0; i < size; i++){
File file=(File)list.get(selectedItemIndexes[i]).get("file");
mimeType = getMIMEType(file);
Uri u = Uri.fromFile(file);
uris.add(u);
}
boolean multiple = uris.size() > 1;
Intent intent = new Intent(multiple ?
android.content.Intent.ACTION_SEND_MULTIPLE
: android.content.Intent.ACTION_SEND);
if (multiple) {
intent.setType("*/*");
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
} else {
intent.setType(mimeType);
intent.putExtra(Intent.EXTRA_STREAM, uris.get(0));
}
startActivity(Intent.createChooser(intent, "Share"));