2011-11-13 76 views
3

我希望用戶能夠從我的Android應用程序中發送電子郵件,所以我有安卓發送電子郵件

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, emailaddress); 
    emailIntent.setType("plain/text"); 
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,message); 
    startActivity(emailIntent); 

,但我不知道我需要做的,如果我想要在這封電子郵件中附加2個.png圖片。

謝謝,

回答

7

試試這個。 但對我來說,它只能在真實設備上工作。

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 

    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, emailaddress); 
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message); 
    emailIntent.setType("image/png"); 

    ArrayList<Uri> uris = new ArrayList<Uri>(); 

    uris.add(Uri.parse("android.resource://" + getPackageName() + "/" + R.drawable.file1)); 
    uris.add(Uri.parse("android.resource://" + getPackageName() + "/" + R.drawable.file2)); 

    emailIntent.putExtra(Intent.EXTRA_STREAM, uris)); 

    startActivity(emailIntent); 
+0

有代碼中的兩個錯誤。對於多個附件,應該使用'Intent.ACTION_SEND_MULTIPLE'。第12行有一個額外的右括號,應該是.putExtra(Intent.EXTRA_STREAM,uris); –

0

試試這個:

Intent iShare; 
iShare = new Intent(Intent.ACTION_SEND); 
iShare.setType("image/png"); 

//below you trying to send the images path it always doens have to be a 
//image in the drawable u can get the captured image or in the gallery :) 
iShare.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+fn.getPath())); 
i.putExtra(Intent.EXTRA_TEXT, "Username: " + usernames + "\nClinic Number: " + clnumber + "\nClinic Name: " + clname + "\nBranch: " + spnnr); 
startActivity(Intent.createChooser(iShare, "Share")); 

try { 
    startActivity(Intent.createChooser(ishare, "Send mail...")); 
} catch (android.content.ActivityNotFoundException ex) { 
    Toast.makeText(secondpage.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show(); 
}