0

I know that it is possible to send email attachments when you have a valid file path and URI.

    final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
emailIntent.setType("plain/text");

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

String[] filePaths = new String[] {image1 Path,image2 path};
for (String file : filePaths) {
    File fileIn = new File(file);
    Uri u = Uri.fromFile(fileIn);
    uris.add(u);
}

if ( !(app_preferences.getString("email", "") == null || app_preferences.getString("email", "").equals(""))) {
    emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] {app_preferences.getString("email", "")});    
}

emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject name");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Please find the attachment.");
emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);

startActivity(Intent.createChooser(emailIntent, "Email:"));

I store my images in a DB (as BLOB). (I know it is considered as not a good practice but I've got enough good reasons to do so).

I know it's possible to select the images out of the DB, store it in the SD, send email, and then deleting the images off the SD card, but I'm not looking for this kind of solution.

So, is it possible just to attach a bitmap without any actual file path(since it's stored in my DB).

idish
  • 3,190
  • 12
  • 53
  • 85

1 Answers1

0

Yes, you can

convert your blob to a byte array and then use JavaMail's ByteArrayDataSource to attach it.

Dani
  • 1,220
  • 7
  • 22
  • Great, I'll be looking further into this soon, BTW, I'm also looking to be able to share to all the other shareable activities like WhatsApp, Bluetooth, ETC.. Is it possible also? – idish Aug 20 '13 at 22:27
  • Also, one more question: Will Gmail for example will be able to parse the ByteArrayDataSource back to an image? – idish Aug 20 '13 at 22:29
  • I've been trying to look for some documentation on the ByteArrayDataSource but links are broken. I found this answer : http://stackoverflow.com/a/1502775/1203043 If I change the pdf to png attachment, will it work? – idish Aug 20 '13 at 22:40
  • here is an example on how to do it with oracle, hopefully you can modify it to your needs http://www.jguru.com/faq/view.jsp?EID=498439 – Dani Aug 21 '13 at 03:49