2013-02-11 37 views
0
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
     emailIntent.setType("image/jpg"); 
     emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] 
     {"[email protected]"}); 
     emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, 
     "Test Subject"); 
     emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, 
     "go on read the emails"); 
     Log.v(getClass().getSimpleName(), "sPhotoUri=" + Uri.parse("file:///sdcard/2944154479.jpg")); 
     emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/2944154479.jpg")); 
     startActivity(Intent.createChooser(emailIntent, "Send mail...")); 

我用上面的代碼的圖像發送到電子郵件,電子郵件頁面顯示該文件附加 但我只得到了消息,附件是沒有得到我的郵件。附加的圖像是沒有得到到郵件

請幫助 在此先感謝

回答

0

請嘗試以下代碼,它會爲你工作。

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
      emailIntent.setType("jpeg/image"); 
      emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, 
         new String[] { "" }); 
      emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "subject"); 
      Date cal = Calendar.getInstance().getTime(); 
      emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "body"); 

      Uri uri = Uri.fromFile(new File(Environment 
         .getExternalStorageDirectory(), "/HB.jpg")); 

      emailIntent.putExtra(Intent.EXTRA_STREAM, uri); 
      emailIntent.setType("text/plain"); 

      startActivity(Intent.createChooser(emailIntent, "Send mail...")); 
+0

它不工作,我有沒有需要添加任何其他 – user1891910 2013-02-11 10:58:28

+0

你得到任何錯誤? – Hasmukh 2013-02-11 11:00:06

+0

不,在發送電子郵件時顯示它已附加,但是當我發送並檢查我的郵件時,它沒有收到。 – user1891910 2013-02-11 11:04:03

0

您首先必須將類型設置爲text/plain以添加您的消息。然後,您將類型設置爲jpeg/image以添加圖像。否則你的信息將被誤解。

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,getResources().getString(R.string.emlSendToFriendSubject)); 
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[]{emailto}); 
    emailIntent.setType("text/plain"); 
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,getResources().getString(R.string.emlSendToFriendBody)); 
    File file = getFileStreamPath(EMAIL_TEMP_FILE); 
    emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 
    emailIntent.setType("image/jpeg"); 
    emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+file.getAbsolutePath())); 
    startActivityForResult(Intent.createChooser(emailIntent, getResources().getString(R.string.btnSendToFriend)),ActMain.EMAIL_DONE); 
0

試試這個:)

String path = ...; 

//Need to remove file:////, it has to be something like this storage/emulated/0/repertory/image.jpg 
if(path.startsWith("file")){ 
    path = path .replace("file:////", ""); 
} 

Intent i = new Intent(Intent.ACTION_SEND); 
i.setType("message/rfc822"); 
i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(path))); 
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"[email protected]"}); 
i.putExtra(Intent.EXTRA_SUBJECT, "Subject"); 
i.putExtra(Intent.EXTRA_TEXT , "body"); 
startActivity(Intent.createChooser(i, "Sending email..."));