2014-02-28 77 views
0

如果我共享圖像一次在Gmail中,並再次回來,做一些改變,如果我分享,然後再次只有以前的圖像顯示:(這是4.1.1的問題,當我4.2.2運行同樣的問題,它完美的作品:(:(:(無法正常共享圖像android

嗨,我怎麼使用這一意圖分享圖片我用下面的代碼

public void otherBtn(View v) { 
    FileOutputStream out = null; 
    try { 
     if (bitmap != null) { 
      bitmap.recycle(); 
      bitmap = null; 
     } 
     Intent sharingIntent = new Intent(Intent.ACTION_SEND); 
     File sdcard = Environment.getExternalStorageDirectory(); 
     File f = new File(sdcard, "temp.jpg"); 
     if (f.isFile()) { 
      f.delete(); 
     } 
     out = new FileOutputStream(f); 
     captureRelativeLayout.setDrawingCacheEnabled(true); 
     bitmap = captureRelativeLayout.getDrawingCache(true).copy(
       Config.ARGB_8888, false); 
     bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out); 

     sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f)); // imageUri 
     sharingIntent.setType("image/jpg"); 
     startActivity(sharingIntent); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } finally { 
     if (out != null) { 
      try { 
       out.flush(); 
       out.close(); 
      } catch (Exception e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 

     } 
    } 
} 

例如,當我分享下面的圖片用以上代碼

enter image description here

其中我以前共享將示出,但不高於更新圖像表示:(

enter image description here

+0

嘗試在開始活動之前刷新並關閉流:'out.flush(); out.close();' –

+0

@still_learning嘗試過,但沒有工作:( –

+0

請更新你的代碼,以便我們可以看到你的嘗試。 –

回答

0

您齊平,並關閉流之後開始活動圖像。您需要在之前正確寫入文件內容。

out = new FileOutputStream(f); 
captureRelativeLayout.setDrawingCacheEnabled(true); 
bitmap = captureRelativeLayout.getDrawingCache(true).copy(
     Config.ARGB_8888, false); 
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out); 

// Flush and close stream 
out.flush(); 
out.close(); 
// Now it's safe to use the file 

sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f)); 
sharingIntent.setType("image/jpg"); 
startActivity(sharingIntent);