如何使用附件发送电子邮件(图片) [英] How to send email with Attachment(Image)
问题描述
我tryed两种方法发送电子邮件
与图像attachment.The附件被显示在写主题的时候,波比一切aftersend该电子邮件在它的只显示了接收器受试者放大器;车身
下面只没有attacthment用户getting.I我不明白发生了什么与我的code worong是我的code。请给我任何建议来完成这个任务。
1型: -
意图picMessageIntent =新的意图(Intent.ACTION_SEND);
picMessageIntent.setType(为image / jpeg);
文件downloadedPic =新的文件(Environment.getExternalStorageDirectory(),strFileName +.JPG); // Art_Nature
picMessageIntent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(downloadedPic)); // screenshotUri); // Uri.fromFile(新文件(downloadedPic))); //Uri.fromFile(downloadedPic)); // Uri.fromFile(新文件(/路径/到/ downloadedPic)));
startActivity(Intent.createChooser(picMessageIntent,分享图像使用));
2型:
的ArrayList<乌里> URI的=新的ArrayList<乌里>();
乌里U;
意图picMessageIntent =新的意图(Intent.ACTION_SEND);
picMessageIntent.setType(为image / jpeg);
文件downloadedPic =新的文件(Environment.getExternalStorageDirectory(),strFileName +.JPG); // Art_Nature
如果(downloadedPic.exists())
{
乌里U1 = Uri.fromFile(downloadedPic);
uris.add(U1);
picMessageIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM,URI的);
startActivity(picMessageIntent);
}
下面是一些可以帮助你。请确保您以适当的方式拼写你的映像文件的路径。不要忘了/分隔符(试图得到一个日志的路径)。此外,还要确保该文件存在。
/ **附加图像到电子邮件和发送电子邮件* /
按钮B1 =(按钮)findViewById(R.id.finalsectionsubmit);
b1.setOnClickListener(新View.OnClickListener(){
@覆盖
公共无效的onClick(视图v){
意图emailIntent =新的意图(android.content.Intent.ACTION_SEND);
// emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,emailSignature);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,toSenders);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,subjectText);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,+的MessageText\ñ\ N+ emailSignature);
emailIntent.setType(为image / jpeg);
文件bitmapFile =新的文件(Environment.getExternalStorageDirectory()+
/"+FOLDER_NAME+"/picture.jpg);
myUri = Uri.fromFile(bitmapFile);
emailIntent.putExtra(Intent.EXTRA_STREAM,myUri);
startActivity(Intent.createChooser(emailIntent,发送的电子邮件:));
eraseContent();
sentMode =真;
}
});
I am tryed two ways to send email
with image attachment.The attachment is displaying at the time of writing subject,boby everything aftersend that email at the receiver it's showing only subject & Body
only no attacthment the user getting.I am not understanding what's worong with my code below is my code. please give my Any suggestion to finish this task.
Type 1:-
Intent picMessageIntent = new Intent(Intent.ACTION_SEND);
picMessageIntent.setType("image/jpeg");
File downloadedPic = new File(Environment.getExternalStorageDirectory(), strFileName + ".jpg");// Art_Nature
picMessageIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(downloadedPic));//screenshotUri );//Uri.fromFile(new File("downloadedPic"))); //Uri.fromFile(downloadedPic)); // Uri.fromFile(new File("/path/to/downloadedPic")));
startActivity(Intent.createChooser(picMessageIntent, "Share image using"));
Type 2:
ArrayList<Uri> uris = new ArrayList<Uri>();
Uri u;
Intent picMessageIntent = new Intent(Intent.ACTION_SEND);
picMessageIntent.setType("image/jpeg");
File downloadedPic = new File(Environment.getExternalStorageDirectory(), strFileName + ".jpg");// Art_Nature
if(downloadedPic.exists())
{
Uri u1 = Uri.fromFile(downloadedPic);
uris.add(u1);
picMessageIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
startActivity(picMessageIntent);
}
Here is something that can help you. Make sure you spelled your image file path in a proper manner. Don't forget the "/" separator (try to get a log of your path). Also, be sure that the file exists.
/** ATTACHING IMAGE TO EMAIL AND SENDING EMAIL */
Button b1 = (Button)findViewById(R.id.finalsectionsubmit);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
// emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailSignature);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, toSenders);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subjectText);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, messageText+"\n\n"+emailSignature);
emailIntent.setType("image/jpeg");
File bitmapFile = new File(Environment.getExternalStorageDirectory()+
"/"+FOLDER_NAME+"/picture.jpg");
myUri = Uri.fromFile(bitmapFile);
emailIntent.putExtra(Intent.EXTRA_STREAM, myUri);
startActivity(Intent.createChooser(emailIntent, "Send your email in:"));
eraseContent();
sentMode = true;
}
});
这篇关于如何使用附件发送电子邮件(图片)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!