Android: using email intent to send email, is it possible to change the message before sending?

I use:

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

in order to send an email, I need to add a footer to the message, is there any listener or in some way that I can edit the message when the user clicks “send”?

Thank!

Edit:

below is the code I used:

private void sendEmail(String recipient, String subject, String message) {
    try {
        final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
        emailIntent.setType("plain/text");
        if (recipient != null)  emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{recipient});
        if (subject != null)    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
        if (message != null)    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);

        startActivity(Intent.createChooser(emailIntent, "Send mail..."));

    } catch (ActivityNotFoundException e) {
        // cannot send email for some reason
    }
}

No type field:

android.content.Intent.EXTRA_EMAIL

which allows me to communicate information about intentions.

+3
source share
3 answers

If the email was sent from your own application, you will need to add a footer before dismissing the intent.

( ), , .

:

message

if (message != null)    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
+2
@Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url.startsWith("mailto:")) { 
                try {
                    Intent emailIntent = new Intent(Intent.ACTION_SEND, Uri.parse(url));
                    emailIntent.setType("message/rfc822");
                    String recipient = url.substring( url.indexOf(":")+1 );
                    if (TextUtils.isEmpty(recipient)) recipient = "loco@wareninja.com";
                    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{recipient});
                    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, mContext.getString(R.string.email_subject));
                    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, mContext.getString(R.string.email_message, " "));

                    mContext.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
                }
                catch (Exception ex) {}
            }
            return true;
        }
+1

..

  • To, Subject Text TextEdit.

  • String.

  • / String

  • emailIntent.putExtra()

Then your users can decide whether they like the changes or not, and just click send.

0
source

All Articles