2013-07-24 103 views
0

我有一個應用程序,其中有一個電子郵件部分,我必須在正文中輸入文本和圖像。我在網上搜索,但沒有找到相應的解決方案。任何幫助將不勝感激。從電子郵件正文附加資源圖片Android

這裏查看:

Google Email/Default Email Client

+0

你試過了什麼? –

回答

1
BitmapFactory.Options bitmapFatoryOptions=new BitmapFactory.Options(); 
     bitmapFatoryOptions.inPreferredConfig=Bitmap.Config.ARGB_8888; 
Bitmap myBitmap=BitmapFactory.decodeResource(getResources(),R.drawable.face4,bitmapFatoryOptions); 

File mFile = savebitmap(myBitmap); 
     Uri u = null; 
     u = Uri.fromFile(mFile); 
     Intent emailIntent = new Intent(Intent.ACTION_SEND); 
     emailIntent.setType("image/*"); 
    Intent.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail"); 
     emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Send Mail"); 
     emailIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.share_texthere)); 
     emailIntent.putExtra(Intent.EXTRA_STREAM, u); 
     startActivity(Intent.createChooser(emailIntent,"Send")); 

代碼saveBitmap()方法:

private File savebitmap(Bitmap bmp) { 
    String temp="SplashItShare"; 
    String extStorageDirectory = Environment.getExternalStorageDirectory().toString(); 
    OutputStream outStream = null; 
    String path = Environment.getExternalStorageDirectory() 
      .toString(); 
    new File(path + "/SplashItTemp").mkdirs(); 
    File file = new File(path+"/SplashItTemp", temp + ".png"); 
    if (file.exists()) { 
     file.delete(); 
     file = new File(path+"/SplashItTemp", temp + ".png"); 
    } 

    try { 
     outStream = new FileOutputStream(file); 
     bmp.compress(Bitmap.CompressFormat.PNG, 100, outStream); 
     outStream.flush(); 
     outStream.close(); 
    } catch (Exception e) { 
     e.printStackTrace(); 
     return null; 
    } 
    return file; 
} 

希望它會爲你工作。

相關問題