Reputation: 437
I am trying to attach multiple images to an email.
I have tried the next code, but I don`t know what I am doing wrong.
I need to call the images by the Integer Array that you will see and attach them to an email.
Some of the class look like this:
Integer[] images = {
R.drawable.image1,
R.drawable.image2,
R.drawable.image3,
R.drawable.image4 };
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.bSendEmail:
Intent emailintent2 = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
emailintent2.setType("plain/text");
emailintent2.putExtra(Intent.EXTRA_EMAIL, emailaddress2);
emailintent2.putExtra(Intent.EXTRA_SUBJECT, corsub);
emailintent2.putExtra(Intent.EXTRA_TEXT, message2);
ArrayList<Uri> uris = new ArrayList<Uri>();
uris.add(Uri.parse("android.resource://" + getPackageName() + "/" + images[0]));
uris.add(Uri.parse("android.resource://" + getPackageName() + "/" + images[1]));
uris.add(Uri.parse("android.resource://" + getPackageName() + "/" + images[2]));
uris.add(Uri.parse("android.resource://" + getPackageName() + "/" + images[3]));
emailintent2.putExtra(Intent.EXTRA_STREAM, uris);
startActivity(emailintent2);
break;
Upvotes: 3
Views: 1518
Reputation: 2928
use
emailintent2.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
instead of
emailintent2.putExtra(Intent.EXTRA_STREAM, uris);
using file
private String root = Environment.getExternalStorageDirectory().getPath()
+ Tags.DIRECTORY_PATH;
path = new ArrayList<String>();
File f = new File(root);
File[] files = f.listFiles();
if (!root.equals(root))
{
item.add(root);
path.add(root);
item.add("../");
path.add(f.getParent());
}
for (int i = 0; i < files.length; i++)
{
File file = files[i];
path.add(file.getPath());
if (file.isDirectory())
item.add(file.getName() + "/");
else
item.add(file.getName());
ArrayList<Uri> uris = new ArrayList<Uri>();
for (String file : path) {
File fileIn = new File(file);
Uri u = Uri.fromFile(fileIn);
uris.add(u);
}
Upvotes: 0
Reputation: 5347
Bad news. It's simply not supported.
Have you thought of creating a ZIP archive of the attachments, and attach the archive?
(Note: Even that does not work good enough for me currently, but many seem to be able to live with it.)
Upvotes: 1