0

I have a simple routine I want to implement but I am not sure if I am going about it the right way. I want to use an emailintent to send a first email then following that to call another emailintent and send a second email (which will be different from the first). In essence I want to sequentially send two emails.

I tried startActivityforResult for the first email and then calling the second emailintent on that request code but this doesn't seem to work (I know Android won't give me a result code if I use StartActivityforResult to send emails externally though that doesn't concern me as the second emailintent should be called regardless of whether first was successful).

Any ideas?

4

2 回答 2

1

您的方法是正确的方法。这是一些在设备上运行的示例代码。

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 1234) {
        Intent sendIntent = new Intent(Intent.ACTION_SEND);
        sendIntent.setType("message/rfc822");
        sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "address2@example.com" });
        // Setup message here
        try {
            getSupportActivity().startActivity(sendIntent);
        } catch (final android.content.ActivityNotFoundException ex) {
            // No email client found
        }
    }
}

public void sendEmail() {
    Intent sendIntent = new Intent(Intent.ACTION_SEND);
    sendIntent.setType("message/rfc822");
    sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "address@example.com" });
    // Setup message here
    try {
        getSupportActivity().startActivityForResult(sendIntent, 1234);
    } catch (final android.content.ActivityNotFoundException ex) {
        // No email client found
    }
}

如果您正在使用片段,请确保 onActivityResult 在 Activity 中,或者确保将 onActivityResult 从 Activity 重定向到片段。

于 2013-05-01T20:57:28.207 回答
0

您可以使用 Javamail API 发送两封不同的电子邮件。我想这可以与 javamail 一起使用。 http://docs.oracle.com/cd/E18930_01/html/821-2418/beaow.html#scrolltoc

(不要忘记导入库并添加互联网权限)

于 2013-04-30T13:12:32.787 回答