【问题标题】:Email with attachment带附件的电子邮件
【发布时间】:2011-11-19 14:29:58
【问题描述】:

我正在尝试使用意图发送带有附件的电子邮件。 该文件是存储在原始文件夹中的pdf。它小于200k。 但它显示文件太大而无法附加。是吗? 请帮帮我..

Intent in = new Intent(Intent.ACTION_SEND);
in.setType("application/pdf");
in.putExtra(Intent.EXTRA_EMAIL,new String[]{email.getText().toString()});
in.putExtra(Intent.EXTRA_SUBJECT, "Android Development Course");
Uri uri = Uri.parse("android.resource://deepak.android.samples/raw/android");
in.putExtra(Intent.EXTRA_STREAM,uri);
startActivity(Intent.createChooser(in, "Sending email.."));

【问题讨论】:

  • 你是怎么做到的?给我们看一些代码。
  • Intent in = new Intent(Intent.ACTION_SEND); in.setType("文本/html"); in.putExtra(Intent.EXTRA_EMAIL,new String[]{email.getText().toString()});
  • in.putExtra(Intent.EXTRA_SUBJECT, "Android 开发教程"); uri uri = Uri.parse("android.resource://deepak.android.samples/raw/android"); in.putExtra(Intent.EXTRA_STREAM,uri);startActivity(Intent.createChooser(in, "发送电子邮件.."));
  • 您可以编辑您的原始帖子并附加代码。点击问题底部的“编辑”按钮并附上您的代码。

标签: android email android-intent


【解决方案1】:

使用这个方法

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, 
                     new String[]{"emailaddress"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Body");

String rawFolderPath = "android.resource://" + getPackageName() 
                       + "/" + R.raw.shortcuts;

// Here my file name is shortcuts.pdf which i have stored in /res/raw folder
Uri emailUri = Uri.parse(rawFolderPath );
emailIntent.putExtra(Intent.EXTRA_STREAM, emailUri);
emailIntent.setType("application/pdf");
startActivity(Intent.createChooser(emailIntent, "Send mail..."));

【讨论】:

    猜你喜欢
    • 2011-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-14
    • 2015-08-28
    • 1970-01-01
    相关资源
    最近更新 更多