0

I want to send image to email. now i am selecting image from gallery and it is displaying in emulator but i need to send same image to email.

enter image description here

My Code is....

Main Activity

 public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == RESULT_OK) {
            if (requestCode == SELECT_PICTURE) {
                // Get the url from data
                Uri selectedImageUri = data.getData();
                if (null != selectedImageUri) {
                    // Get the path from the Uri
                    String path = getPathFromURI(selectedImageUri);
                    Log.i(TAG, "Image Path : " + path);
                    // Set the image in ImageView
                    iv.setImageURI(selectedImageUri);
                }
            }
        }
    }

i was Passing Values as... Last Argument is for Image

 new SendMailTask(Main2Activity.this).execute("hari.androidxxx@gmail.com",
                "unixxxxx", toEmails, "Testing", mbody, ???);//i don't know last argument how to send

Here i Have to Display...

public MimeMessage createEmailMessage() throws AddressException,
            MessagingException, UnsupportedEncodingException {

        mailSession = Session.getDefaultInstance(emailProperties, null);
        emailMessage = new MimeMessage(mailSession);

        emailMessage.setFrom(new InternetAddress(fromEmail, fromEmail));

            Log.i("GMail","toEmail: "+toEmailList);
            emailMessage.addRecipient(Message.RecipientType.TO,
                    new InternetAddress(toEmailList));


        emailMessage.setSubject(emailSubject);
        emailMessage.setContent(emailBody+,"text/html");// Here I have to display
        // emailMessage.setText(emailBody);// for a text email
        Log.i("GMail", "Email Message created.");
        return emailMessage;
    }

Thanks In Advance...

Karthick Anbazhagan
  • 353
  • 2
  • 9
  • 27

1 Answers1

1

Try this. It has worked for me.

Intent shareIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
shareIntent.setType("text/plain");
shareIntent.setPackage("com.google.android.gm"); // This will open Gmail App on user's device
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Email Subject");
shareIntent.putExtra(Intent.EXTRA_TEXT, "Extra text goes here");
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, fileUri); //fileUri is the Uri which is recieved in onActivityResult of Activity from Gallery Intent
startActivityForResult(shareIntent, 12);
Pang
  • 9,564
  • 146
  • 81
  • 122