2012-02-23 5 views
0

私は午前中に問題で戦っており、今ここで尋ねると思いました。電子メールに添付された9個のパッチPNG rawリソースは元のファイルではありません

私は電子メールに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

私はアプリはそれを送信する前にRAWファイルを処理することを疑いますか?

追加情報

私は今、電子メールに添付する前に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); 
    } 
} 
関連する問題