Create Intent Send Email - Android Intent

Android examples for Intent:Send Email

Description

Create Intent Send Email

Demo Code


//package com.java2s;

import android.app.Activity;

import android.content.Intent;

import android.widget.Toast;

public class Main {
    public static void SendEmail(Activity currentActivity,
            String[] recipients, String subject, String body) {
        SendEmail(currentActivity, recipients, subject, body,
                "Send mail...");
    }//from w w  w .j a  va  2s .c  o  m

    public static void SendEmail(Activity currentActivity,
            String[] recipients, String subject, String body,
            String chooserTitle) {
        Intent i = new Intent(Intent.ACTION_SEND);
        i.setType("message/rfc822");
        i.putExtra(Intent.EXTRA_EMAIL, recipients);
        i.putExtra(Intent.EXTRA_SUBJECT, subject);
        i.putExtra(Intent.EXTRA_TEXT, body);
        try {
            currentActivity.startActivity(Intent.createChooser(i,
                    chooserTitle));
        } catch (android.content.ActivityNotFoundException ex) {
            Toast.makeText(currentActivity,
                    "There are no email clients installed.",
                    Toast.LENGTH_SHORT).show();
        }
    }
}

Related Tutorials