2010-12-07 54 views
1

我有一套jpg存儲在我應用程序的可繪製文件夾中。我希望能夠讓用戶按下一個按鈕,讓他們發送這些jpg中的一個。我已經知道我可以使用ACTION_SEND intent,但是我無法將我的drawable文件夾中的jpg附加到intent中。我已經閱讀了其他一些論壇帖子,聽起來要走的路是將我的jpg保存到用戶的外部SD卡上,然後在那裏引用它。如何將我的應用程序的可繪製文件夾中的JPG複製到用戶的外部SD卡上?Android:使用彩信發送本地圖像

+0

你有沒有試過建議的方法? – Zelimir 2010-12-14 10:39:10

回答

0

從資源複製圖像輸出到圖像文件中,你可以使用下面的方法SD卡上的圖片目錄:

Bitmap resourceImage = BitmapFactory.decodeResource(this.getResources(), R.drawable.resource_image1);  
File externalStorageFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "resource_image1.jpg"); 
ByteArrayOutputStream bytes = new ByteArrayOutputStream(); 
resourceImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes); 
byte b[] = bytes.toByteArray(); 

try 
{ 
    externalStorageFile.createNewFile(); 
    OutputStream filoutputStream = new FileOutputStream(externalStorageFile); 
    filoutputStream.write(b); 
    filoutputStream.flush(); 
    filoutputStream.close(); 
} 
catch (IOException e) 
{ 
} 

然後你就可以將它指定ACTION_SEND意圖圖像附件。