0

我对android还很陌生,我的电子邮件有问题。我正在尝试将文本文件附加到电子邮件并发送,但是当我这样做时,我收到“文件太大”错误。这是我第一次在应用程序中设置电子邮件,有人可以帮忙吗?

代码:

    File myFile = new File(Environment.getExternalStorageDirectory() + "/test.txt");
    Uri uri = Uri.fromFile(myFile);

    Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);  

    String aEmailList[] = { "person@gmail.com" };    
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);     
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Test");  
    emailIntent.setType("plain/text");  
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "This is a test.");
    emailIntent.putExtra(Intent.EXTRA_STREAM, uri);

    startActivity(emailIntent);   
4

1 回答 1

0

你好,试试这个。

public void sendMail(String[] mailTo,String[] cc,String subject, String body, String attachmentFilePath)
{
    Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    emailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    emailIntent.addFlags(Intent.FLAG_FROM_BACKGROUND);

    emailIntent.setType("plain/text");

    if(mailTo!=null)
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,mailTo);
    if(cc!=null)
    emailIntent.putExtra(android.content.Intent.EXTRA_CC, cc);
    if(subject!=null)
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
    if(body!=null)
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(body));
    if(mailTo!=null)
    emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+attachmentFilePath));

    context.startActivity(emailIntent); 
}
于 2015-08-19T05:11:38.480 回答