我如何通过一个Intent共享多个文件?

编程入门 行业动态 更新时间:2024-10-10 03:23:08
本文介绍了我如何通过一个Intent共享多个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

下面是我的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.

更多推荐

我如何通过一个Intent共享多个文件?

本文发布于:2023-11-28 08:53:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641743.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   文件   Intent

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!