Create Intent to send Email - Android Intent

Android examples for Intent:Send Email

Description

Create Intent to send Email

Demo Code


//package com.java2s;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;

public class Main {
    public static void sendEmail(Context context, String recipient,
            String subject, String body) {
        StringBuilder builder = new StringBuilder("mailto:"
                + Uri.encode(recipient));
        if (subject != null) {
            builder.append("?subject=" + subject);
            if (body != null) {
                builder.append("&body=" + body);
            }// ww w  .jav a  2 s.  c  o  m
        }
        String uri = builder.toString();
        Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse(uri));
        intent.addFlags(intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }
}

Related Tutorials