-1

I am creating a application where i want to send captured image as an attachment to email body but not able to achieve above.Can anyone please guide me.

 emailsend.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Log.i("Send email", "");
            String[] TO = {""};
            String[] CC = {""};
            Intent emailIntent = new Intent(Intent.ACTION_SEND);

            emailIntent.setData(Uri.parse("mailto:"));
            emailIntent.setType("application/image");
            emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
            emailIntent.putExtra(Intent.EXTRA_CC, CC);
            emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Your subject");
            emailIntent.putExtra(Intent.EXTRA_TEXT, "Email message goes here");
            emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(pic));
            try {
                startActivity(Intent.createChooser(emailIntent, "Send mail..."));
                finish();
                Log.i("Finished sending", "");
            } catch (android.content.ActivityNotFoundException ex) {
                Toast.makeText(clickimages.this, "There is no email client installed.", Toast.LENGTH_SHORT).show();
            }
        }
    });'
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • show what you've done so far – shinilms Dec 06 '18 at 06:46
  • Duplicate [Count1](https://stackoverflow.com/questions/27228136/how-to-send-image-as-body-content-in-mail-android) [Count2](https://stackoverflow.com/questions/30435051/what-are-the-possible-ways-to-send-image-via-email-in-android) [Count3](https://stackoverflow.com/questions/15563583/how-to-send-mail-with-an-image-as-an-attachment-in-android) – Agilanbu Dec 06 '18 at 06:50

1 Answers1

0

To add an image to an email you are trying to send you can do the following :

Uri uri = Uri.parse("file://" + filepath);
intent(Intent.EXTRA_STREAM, uri);

Where intent is the operation to send your mail and the path to your image is found in the filepath variable.

halfer
  • 19,824
  • 17
  • 99
  • 186
tomerpacific
  • 4,704
  • 13
  • 34
  • 52