0
votes

I want to send email with multiple attachment in android i got solution for that but now the problem is that i have 2 files one in SDCard and other in local directory of android i.e Drawable folder. I have done with coding while sending email it is showing both attachment but i am receiving only one attachment which is present in SDcard i am not able to get the attachment from internal folder i.e drawable. Below is my code please help me to solve this.

public class TransmitAgreement extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_transmit_agreement);

    String addressLine = gpsTracker.getAddressLine(this);
    String emailaddress = "myemail";
    String message = "Msg"
    String subject = "sbj";

    Intent emailIntent = new Intent(
            android.content.Intent.ACTION_SEND_MULTIPLE);
    emailIntent.setType("text/plain");
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
            new String[] { emailaddress });
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
    emailIntent.putExtra(Intent.EXTRA_TEXT, message);
    ArrayList<Uri> uris = new ArrayList<Uri>();
    // convert from paths to Android friendly Parcelable Uri's
    String[] filePaths = new String[] {
            "android.resource://com.example.freenup/" + R.drawable.freenup_app_agreement,
            "sdcard/saved_images/MyImage.png" };
    for (String file : filePaths) {
        File fileIn = new File(file);
        Uri u = Uri.fromFile(fileIn);
        uris.add(u);
    }
    emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
    startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.transmit_agreement, menu);
    return true;
}
}

I have tried with other solution too but getting same problem. I am only geeting one attachment in email...

1

1 Answers

2
votes

i think you can't not directly send attachment from drawable folder

so try with this way

    try
            {
            Intent email = new Intent(Intent.ACTION_SEND_MULTIPLE);
            email.setType("plain/text");
            email.putExtra(Intent.EXTRA_EMAIL, new String[] {"email id"});
            email.putExtra(Intent.EXTRA_SUBJECT, "That one works");
            FileOutputStream outStream; 
            File file;

            Bitmap bm = BitmapFactory.decodeResource( getResources(), R.drawable.ic_launcher);
                    String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
            file = new File(extStorageDirectory, "ic_launcher.PNG");
            try {
                outStream = new FileOutputStream(file);
                bm.compress(Bitmap.CompressFormat.PNG, 100, outStream);
                outStream.flush();
                outStream.close();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }

            File[] f = new File[2];
            f[0] = new File("/mnt/ext_card/Download/test.jpg");
            f[1] = file;

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

            for(int i=0;i<f.length;i++)

              {

                Uri u = Uri.fromFile(f[i]);
                uris.add(u);

              }

            email.putExtra(Intent.EXTRA_EMAIL, new String[] { "" });
            email.putExtra(Intent.EXTRA_SUBJECT, "My Subject");
            email.putExtra(Intent.EXTRA_TEXT, "");
            email.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
            startActivity(Intent.createChooser(email, "Choose an Email client :"));

            }

            catch (Exception e) {

                e.toString();

            }