2012-02-23 37 views
0

我一直在一個問題整個上午奮鬥,並認爲我現在要問這裏。9貼片png原始資源附加到電子郵件是不是原始文件

我用下面的代碼9個圖像附加到電子郵件:

sendIntent.setType("image/png"); 

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

uris.add(Uri.parse("android.resource://com.android9patch.viewer/raw/" + mBaseFilename + String.format("%05d", mAppBackgroundCurrentFile))); 

sendIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); 
startActivity(Intent.createChooser(sendIntent, "Email:")); 

的問題是,當我收到的電子郵件,圖像是不是原來的9補丁,但版本沒有規模和填充標記。

我應該得到這樣的結果: Expected result attachment

,但我得到這個代替: Result received

我懷疑是應用處理原始文件發送之前?

信息

我現在試圖將文件複製到SD卡保存附加到電子郵件之前。那麼,出於某種原因,即使複製也會刪除比例和填充標記...我不明白。

這是我從raw copy function拿的複印功能。

private boolean copyToSDCard(int resourceID, String finalName) 
{ 
    String extStorageDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString(); 
    OutputStream out = null; 

    try 
    { 
     InputStream in = getResources().openRawResource(resourceID); 
     out = new FileOutputStream(extStorageDirectory + "/" + finalName + ".9.png"); 
     copyFile(in, out); 
     in.close(); 
     in = null; 
     out.flush(); 
     out.close(); 
     out = null; 
    } 
    catch (Exception e) 
    { 
     Log.e("copyToSDCard", e.toString()); 
     e.printStackTrace(); 
    } 

    return false; 
} 

private void copyFile(InputStream in, OutputStream out) throws IOException { 
    byte[] buffer = new byte[1024]; 
    int read; 
    while((read = in.read(buffer)) != -1){ 
     out.write(buffer, 0, read); 
    } 
} 

回答

0

我結束了資產複製到SD卡,並使用以下功能這個新的文件附加到電子郵件:

... 
if(copyAssetToSDCard(filename, basepath + filename)) 
{ 
    uris.add(Uri.parse("file://" + basepath + filename)); 
} 
... 


private boolean copyAssetToSDCard(String SrcFilename, String DstFilename) 
{ 
    OutputStream out = null; 

    try 
    { 
     AssetManager assetManager = getResources().getAssets(); 
     InputStream in = assetManager.open(SrcFilename); 
     out = new FileOutputStream(DstFilename); 
     copyFile(in, out); 
     in.close(); 
     in = null; 
     out.flush(); 
     out.close(); 
     out = null; 

     return true; 
    } 
    catch (Exception e) 
    { 
     Log.e("copyToSDCard", e.toString()); 
     e.printStackTrace(); 
    } 

    return false; 
} 

private void copyFile(InputStream in, OutputStream out) throws IOException { 
    byte[] buffer = new byte[1024]; 
    int read; 
    while((read = in.read(buffer)) != -1){ 
     out.write(buffer, 0, read); 
    } 
} 
相關問題