共享多个文件
//共享多个文件代码如下
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"));
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步