2012-07-23 53 views
2

在我的android應用程序中,我通過藍牙共享圖像正在工作。同時我試圖通過郵件分享。但圖像不附加該郵件。它只與身體一起發送。 任何解決方案?在Android中通過郵件分享圖像

+0

哪裏是你的代碼? – 2012-07-23 03:05:23

回答

4

要通過電子郵件發送圖像作爲附件,您首先需要將其保存爲SD卡上的文件。如果你的形象是一個Bitmap,那麼你可以將其寫入文件中像下面

OutputStream fOut = null; 
String fileName = Environment.getExternalStorageDirectory()+"/myImage.png"; 
File file = new File(fileName); 
fOut = new FileOutputStream(file); 
bitmap.compress(Bitmap.CompressFormat.PNG, 85, fOut); 
fOut.flush(); 
fOut.close(); 

然後使用Intent,與圖像文件啓動電子郵件客戶端應用程序作爲附件

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
emailIntent.setType("image/jpeg"); 
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {""}); 
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, EMAIL_SUBJECT); 
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, EMAIL_BODY); 
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+fileName)); 
startActivity(Intent.createChooser(emailIntent, "Sharing Options"));