我想将图片发送到电子邮件。现在我从图库中选择图像,它在模拟器中显示,但我需要将相同的图像发送到电子邮件。
我的代码是......
主要活动
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);
}
}
}
}
我将值传递为...最后一个参数是图像
new SendMailTask(Main2Activity.this).execute("hari.androidxxx@gmail.com",
"unixxxxx", toEmails, "Testing", mbody, ???);//i don't know last argument how to send
我必须在这里展示......
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;
}
提前致谢...
答案 0 :(得分:1)
试试这个。它对我有用。
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);