0

我正在使用下面的代码向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..."));

提前致谢。

4

1 回答 1

1

尝试以下操作:

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 示例应用程序,它执行此操作: Code Project Send Mail With Attachment Example

于 2013-05-20T08:05:55.000 回答