1

我想在邮件中附加文件....问题是我想使用ACTION_SENDTO。当我发送没有附件的邮件时,它工作正常,但是当我尝试附加文件时,它给出了一个异常(android.content.ActivityNotFoundException),就像下面的链接: 如何使用附加图像启动电子邮件意图

我尝试了其中的答案,但没有解决。这是我的代码

Uri mail= Uri.fromParts("mailto",message, null);                                
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, mail);                
emailIntent.putExtra(Intent.EXTRA_SUBJECT, sub);
emailIntent.putExtra(Intent.EXTRA_TEXT, mailcontent);               
emailIntent.setData(Uri.parse("file://" + Environment.getExternalStorageDirectory()+"/ab.jpg"));
emailIntent.setType("image/jpg"); 
startActivity(emailIntent);
4

3 回答 3

0

Need to use the EXTRA_STREAM

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

        Uri outputFileUri = Uri.fromFile( file );
        emailIntent.putExtra(android.content.Intent.EXTRA_STREAM, outputFileUri);
于 2013-06-21T19:53:34.883 回答
0

尝试这个 :

    private static final String MESSAGE_RFC822 = "message/rfc822";
    private static final String SELECT_EMAIL_APPLICATION = "Select email application.";

    public static void sendEmail(Context theContext, final String title, final String[] emails, final String theSubject, final String theBody,
        final File file) throws ActivityNotFoundException
{
    final Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType(MESSAGE_RFC822);
    intent.putExtra(Intent.EXTRA_EMAIL, emails);
    intent.putExtra(Intent.EXTRA_SUBJECT, theSubject);
    intent.putExtra(Intent.EXTRA_TEXT, theBody);
    if (file != null) {
        intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + file.getAbsolutePath()));
    }

    theContext.startActivity(Intent.createChooser(intent, SELECT_EMAIL_APPLICATION));
}
于 2013-06-21T20:11:46.430 回答
0

请使用Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent .putExtra(Intent.EXTRA_STREAM, uri);

于 2013-06-21T19:49:24.830 回答