2012-03-25 180 views
0

我试了两种方式send email与图像attachment.The附件显示在撰写时的主题,boby一切事后发送电子邮件在接收器它只显示subject & Body只有没有attacthment用户越来越多。我不明白什么是我的代码下面是我的代码。请给我任何建议来完成这项任务。如何发送电子邮件与附件(图片)

类型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")); 

类型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); 
    } 

回答

4

这里是东西,可以帮助你。确保你以正确的方式拼写你的图像文件路径。不要忘记“/”分隔符(尝试获取路径的日志)。另外,请确保该文件存在。

/** 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; 
     } 
    }); 
在这个
+0

,什么是eraseContent()和sentmode – Aerrow 2013-04-17 10:07:27

+0

eraseContent()是一个私有方法和sentMode是一个标志。你不需要他们发送电子邮件。上面贴出的代码来自Android项目。 – Radu 2013-04-17 10:16:32

+0

好的谢谢你的回复 – Aerrow 2013-04-17 10:36:52