1

I want to attach file in a mail....The thing is I want to use ACTION_SENDTO .When I send the mail without an attachment it works fine but when I try to attach a file it gives an exception (android.content.ActivityNotFoundException) just like the following link: How to launch email intent with an attached image

I tried what the answer in that said but didn't get it fixed. Here's my code

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);
Community
  • 1
  • 1
user2429689
  • 149
  • 1
  • 3
  • 8

3 Answers3

0

Please use Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
and emailIntent .putExtra(Intent.EXTRA_STREAM, uri);

MDMalik
  • 3,951
  • 2
  • 25
  • 39
  • 1
    No.... I want to use only ACTION_SENDTO as i want to filter out 15+ applications that show up with ACTION_SEND....One could say use settype("message/rfc822") which filters out most of them but still some applications like skype still pop up – user2429689 Jun 22 '13 at 09:12
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);
SashiOno
  • 184
  • 2
  • 7
  • @user850688-I guess when i said "I want to use ACTION_SENDTO" it clearly meant that i don't need answers with ACTION_SEND – user2429689 Jun 22 '13 at 09:08
0

Try this :

    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));
}
Yakiv Mospan
  • 8,174
  • 3
  • 31
  • 35
  • 1
    As i said I only want to use ACTION_SENDTO because even after specifying the mime type to "message/rfc822" applications such as skype responds to the Intent call which I don't want... – user2429689 Jun 22 '13 at 09:06