如何在Android中共享* .txt文件 [英] How to share *.txt file in android
本文介绍了如何在Android中共享* .txt文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试了很多方法,但我做不到。
I tried many ways but i can't do this .
我有一个 *。txt 文件。我想通过 Bluetooth,wifi,电子邮件和...共享它。
I have a *.txt file . i want share it via Bluetooth , wifi , email and ...
.
当我使用此代码时,我无法共享文件:
When i used this code i cant share the file:
File file = new File(Environment.getExternalStorageDirectory(), "Email-Ghap/Emails.txt");
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("*/txt");
sharingIntent.putExtra(Intent.EXTRA_STREAM, file);
startActivity(Intent.createChooser(sharingIntent, "share file with"));
我完全想要这样:当用户单击共享按钮并选择一个电子邮件发件人,例如 Gmail 进行共享。该文件必须为新电子邮件的附件...
Totally i want this : when user clicked on share button and choose one email sender like Gmail for sharing . the file must be attached file for new email ...
我发现此链接 https://stackoverflow.com/a/16036249/4016922
但它共享txt文件内容。我想共享文件而不是txt文件的内容
But it share txt file content . i want to share file not content of txt file
推荐答案
像这样更改代码。
发件人
File file = new File(Environment.getExternalStorageDirectory(), "Email-Ghap/Emails.txt");
到
File file = new File(Environment.getExternalStorageDirectory() + "/" + "Email-Ghap/Emails.txt");
来自:
sharingIntent.setType("*/txt");
到
sharingIntent.setType("text/*");
所以您的最终代码看起来像
so yourFinal Code Looks Like
File file = new File(Environment.getExternalStorageDirectory().toString() + "/" + "abc.txt");
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/*");
sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + file.getAbsolutePath()));
startActivity(Intent.createChooser(sharingIntent, "share file with"));
这篇关于如何在Android中共享* .txt文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文