2016-04-25 139 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

它不工作! –

相关问题