下面是我的code,但是这是对一个单一的文件溶液
我可以共享多个文件和放大器;上传像我这样的单个文件下面?
按钮BTN =(按钮)findViewById(R.id.hello);
btn.setOnClickListener(新OnClickListener(){
@覆盖
公共无效的onClick(视图v){
意向意图=新的意图(Intent.ACTION_SEND);
字符串路径= Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)+/pic.png;
档案文件=新的文件(路径);
MimeTypeMap类型= MimeTypeMap.getSingleton();
intent.setType(type.getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(路径)));
intent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(文件));
intent.putExtra(Intent.EXTRA_TEXT,1111);
startActivity(意向);
}
});
解决方案
是的,但你需要使用 Intent.ACTION_SEND_MULTIPLE
而不是意向.ACTION_SEND
。
意向意图=新的意图();
intent.setAction(Intent.ACTION_SEND_MULTIPLE);
intent.putExtra(Intent.EXTRA_SUBJECT,这里有一些文件。);
intent.setType(为image / jpeg); / *这个例子是分享JPEG图像。 * /
ArrayList的<乌里>文件=新的ArrayList<乌里>();
对于(字符串路径:filesToSend / *您要发送* /中的文件列表){
档案文件=新的文件(路径);
开放的我们的uri = Uri.fromFile(文件);
files.add(URI);
}
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM,文件);
startActivity(意向);
这绝对可以简化,但我留在,所以你可以在需要的每一步打破一些行。
Here is my code, but this is for a single file solution.
Can I share multiple files & uploads like I do for single files below?
Button btn = (Button)findViewById(R.id.hello);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_SEND);
String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/pic.png";
File file = new File(path);
MimeTypeMap type = MimeTypeMap.getSingleton();
intent.setType(type.getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(path)));
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
intent.putExtra(Intent.EXTRA_TEXT, "1111");
startActivity(intent);
}
});
解决方案
Yes but you'll need to use Intent.ACTION_SEND_MULTIPLE
instead of Intent.ACTION_SEND
.
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND_MULTIPLE);
intent.putExtra(Intent.EXTRA_SUBJECT, "Here are some files.");
intent.setType("image/jpeg"); /* This example is sharing jpeg images. */
ArrayList<Uri> files = new ArrayList<Uri>();
for(String path : filesToSend /* List of the files you want to send */) {
File file = new File(path);
Uri uri = Uri.fromFile(file);
files.add(uri);
}
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files);
startActivity(intent);
This could definitely be simplified but I left some lines in so you can break down each step that is needed.