Android 启动Gmail发送带有附件的邮件

Android 启动Gmail发送带有附件的邮件,android,gmail,Android,Gmail,在我的应用程序中,用户有机会导出和导入其数据文件,我还想添加通过邮件作为附件发送此数据文件的选项。 我该怎么做? 感谢您的帮助。我发送带有图像附件的电子邮件的代码: public void sendViaEmail(String pAttachmentPath, String pSubjectLine) { Intent emailIntent = new Intent(Intent.ACTION_SEND); emailIntent.putExtra(android.conte

在我的应用程序中,用户有机会导出和导入其数据文件,我还想添加通过邮件作为附件发送此数据文件的选项。 我该怎么做?
感谢您的帮助。

我发送带有图像附件的电子邮件的代码:

public void sendViaEmail(String pAttachmentPath, String pSubjectLine) {
    Intent emailIntent = new Intent(Intent.ACTION_SEND);
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, pSubjectLine);
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, 
            "Screenshot ****************");
    emailIntent.setType("image/jpeg");
    emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile("file://" + pAttachmentPath));
    mActivity.startActivity(emailIntent);
}


清单上有什么东西要加吗?我得到一个ForceClose。@Andronienn:使用Eclipse中的adb logcat、DDMS或DDMS透视图来检查logcat,并查看与“ForceClose”关联的堆栈跟踪。@Dongshencn:第一个
setType()
是不必要的,因为您稍后会再次调用
setType()
。它还有错误的MIME类型(它将是
text/plain
而不是
plain/text
)。另外,我建议使用
Uri.fromFile()
而不是
Uri.parse()
和串联——这样更简单、更可靠。@commonware:我的MIME类型是什么?设置它重要吗?我有一个扩展名为.dat的文件。@commonware:
08-22 14:48:31.360:ERROR/AndroidRuntime(360):未捕获处理程序:线程主线程由于未捕获异常而退出08-22 14:48:31.382:ERROR/AndroidRuntime(360):android.content.ActivityNotFoundException:找不到处理Intent的活动{act=android.Intent.action.SEND(有附加项)}
public void sendViaEmail(File pAttachmentFile, String pSubjectLine) {
    Intent emailIntent = new Intent(Intent.ACTION_SEND);
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, pSubjectLine);
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, 
            "Screenshot ****************");
    emailIntent.setType("image/jpeg");
    emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(pAttachmentFile));
    mActivity.startActivity(emailIntent);
}