Mona
Mona

Reputation: 6175

Android send email with text and images

I want the user to be able to send an email from inside my android app, so I have

    Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, emailaddress);
    emailIntent.setType("plain/text");
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,message);
    startActivity(emailIntent);

but I don't know what I need to do if I want to have 2 .png images attached to this email also.

Thanks,

Upvotes: 3

Views: 9257

Answers (2)

Rasha Ahamed
Rasha Ahamed

Reputation: 271

Try this:

Intent iShare;
iShare = new Intent(Intent.ACTION_SEND);
iShare.setType("image/png");

//below you trying to send the images path it always doens have to be a
//image in the drawable u can get the captured image or in the gallery :)
iShare.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+fn.getPath()));
i.putExtra(Intent.EXTRA_TEXT, "Username: " + usernames + "\nClinic Number: " + clnumber + "\nClinic Name: " + clname + "\nBranch: " + spnnr);
startActivity(Intent.createChooser(iShare, "Share"));

try {
    startActivity(Intent.createChooser(ishare, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
    Toast.makeText(secondpage.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}

Upvotes: 0

BenDr0id
BenDr0id

Reputation: 156

Try out this one. But for me it is only working on a real device.

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

    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, emailaddress);
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
    emailIntent.setType("image/png");

    ArrayList<Uri> uris = new ArrayList<Uri>();

    uris.add(Uri.parse("android.resource://" + getPackageName() + "/" + R.drawable.file1));
    uris.add(Uri.parse("android.resource://" + getPackageName() + "/" + R.drawable.file2));

    emailIntent.putExtra(Intent.EXTRA_STREAM, uris));

    startActivity(emailIntent);

Upvotes: 9

Related Questions