如何在android中使用intent发送附加文件?

如何在android中使用intent发送附加文件?,android,android-intent,Android,Android Intent,我正在使用下面的代码向gmail发送电子邮件。在这里,我直接打开gmail的撰写邮件。它工作正常。但我需要将文件附加到该邮件中。我该怎么办? 有人能帮我吗 我的代码是: Intent send = new Intent(Intent.ACTION_SENDTO); String uriText = "mailto:" + Uri.encode("user@gmail.com") + "?subject=" + Uri.enco

我正在使用下面的代码向gmail发送电子邮件。在这里,我直接打开gmail的撰写邮件。它工作正常。但我需要将文件附加到该邮件中。我该怎么办? 有人能帮我吗

我的代码是:

Intent send = new Intent(Intent.ACTION_SENDTO);
            String uriText = "mailto:" + Uri.encode("user@gmail.com") + 
                      "?subject=" + Uri.encode("Testing app") + 
                      "&body=" + Uri.encode("Hi,this is android app testing");
            Uri uri = Uri.parse(uriText);

            send.setData(uri);
            startActivity(Intent.createChooser(send, "Send mail..."));
提前感谢。

尝试以下方法:

Uri.fromFile(file);
send.putExtra(Intent.EXTRA_STREAM, uri);
编辑并尝试此选项,然后:

intent.setType("application/zip"); //if it's a zip otherwise whatever you file formap is.
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + zipDestinationString));
如果您希望使用gmail,您需要明确您想要使用的确切目的:

intent.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");

//note one might generate an exception so you should catch the exception and try the other.


intent.setClassName("com.google.android.gm", "com.google.android.gm.ConversationListActivity");
这里还有一个CodeProject示例应用程序,它可以:

您可以在stackoverlow本身上搜索。有很多类似的帖子。文件附件使用下面的代码工作。但它是开放的gmail、电子邮件、Skype等。。但我需要直接撰写邮件。意向电子邮件=新意向(意向.行动\发送);email.setType(“message/rfc822”);email.putExtra(Intent.EXTRA_email,新字符串[]{“suman。chidurala546@gmail.com" }); email.putExtra(Intent.EXTRA_主题,“简历”);email.putExtra(Intent.EXTRA_文本,“请查找附件”);email.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(myFile));startActivity(Intent.createChooser(电子邮件,“电子邮件:文本文件”);我不明白,那是什么问题呢?尝试更好地修改您的问题。我使用上述代码发送附件。但是,当单击“发送”按钮时,它将打开所有已安装的邮件应用程序,如gmail、yahoo、Skype等。但我想直接打开gmail。我不需要所有不必要的应用程序。但我使用的是第一个发布的代码。它直接打开gmail,但我无法附加文件。哦,那么让我修改一下答案。你的问题不清楚。使用intent.setClassName(“com.google.android.gm”,“com.google.android.gm.composeActivityMail”);这段代码在android版本4.1.1中运行良好,但在2.2中,我没有在compose mail中看到任何附加文件。