2016-04-25 198 views
0

請在標記它重複之前仔細閱讀我的問題。謝謝:)ANDROID |只發送電子郵件附件與電子郵件客戶端

我想發送附件的電子郵件。我已經使用ACTION_SENDTO

代碼:

Intent intent = new Intent(Intent.ACTION_SENDTO); 
intent.setData(Uri.parse("mailto:")); 
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{ 
      Wrapper.INSTANCE.getSupportEmail()}); 
intent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(resourceTitleId)); 
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + filePath)); 

try { 
     ctx.startActivity(Intent.createChooser(intent, "Send mail...")); 
} catch (android.content.ActivityNotFoundException ex) { 
     Toast.makeText(ctx, "There are no email clients installed.", 
         Toast.LENGTH_SHORT).show(); 
} 

它僅顯示電子郵件客戶端,見下圖:

test

但附件不除GMAIL工作。

我也試圖與ACTION_SEND實現它

CODE:

Intent intent = new Intent(Intent.ACTION_SEND); 
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{ 
        Wrapper.INSTANCE.getSupportEmail()}); 
intent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(resourceTitleId)); 
intent.setType("message/rfc822"); 
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + filePath)); 

它顯示了所有支持的應用程序,請參見下面的圖片:

enter image description here

但附件是所有電子郵件客戶端上的工作文件。

我在許多堆棧溢出閱讀回答說

intent.setType("message/rfc822");

這將解決我的問題。但事實並非如此。

我只想顯示也支持附件的電子郵件客戶端。

回答

0
String recepientEmail = ""; // either set to destination email or leave empty 

Intent intent = new Intent(Intent.ACTION_SENDTO); 
intent.setData(Uri.parse("mailto:" + recepientEmail)); 
startActivity(intent); 

重點是使用ACTION_SENDTO作爲操作和mailto:作爲數據。如果您想讓用戶指定目標電子郵件地址,請使用mailto:;如果指定電子郵件發送給自己,用郵寄地址:[email protected]

建議的方法篩選所有的應用程序,可以發送電子郵件(如默認的電子郵件應用程序或Gmail)

+0

它不工作! –

相關問題