2012-03-25 131 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