Here you can find the source of sendEmail(@Nonnull Context context, @Nullable String chooserMessage, @Nullable String recipient, @Nullable String subject, @Nullable String message)
Parameter | Description |
---|---|
context | The Context to start the chooser intent with |
chooserMessage | The (optional) message to display in the intent chooser |
recipient | The email address to send the message to |
subject | The subject of the message |
message | The email message |
public static void sendEmail(@Nonnull Context context, @Nullable String chooserMessage, @Nullable String recipient, @Nullable String subject, @Nullable String message)
//package com.java2s; /*//from w ww. j a v a 2 s . c o m * Copyright 2013 Luluvise Ltd * Copyright 2013 Marco Salis - fast3r(at)gmail.com * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import javax.annotation.Nonnull; import javax.annotation.Nullable; import android.app.Activity; import android.content.Context; import android.content.Intent; public class Main { /** * Create a chooser intent to open the email composer with the specified * single email recipient, subject and message. * * @param context * The {@link Context} to start the chooser intent with * @param chooserMessage * The (optional) message to display in the intent chooser * @param recipient * The email address to send the message to * @param subject * The subject of the message * @param message * The email message */ public static void sendEmail(@Nonnull Context context, @Nullable String chooserMessage, @Nullable String recipient, @Nullable String subject, @Nullable String message) { sendEmail(context, chooserMessage, new String[] { recipient }, subject, message); } /** * Create a chooser intent to open the email composer with the specified * email recipients, subject and message. * * Note: if the passed {@link Context} is not an activity, the flag * {@link Intent#FLAG_ACTIVITY_NEW_TASK} will automatically be set to avoid * an Android runtime exception. * * @param context * The {@link Context} to start the chooser intent with * @param chooserMessage * The (optional) message to display in the intent chooser * @param recipients * The email addresses array to send the message to * @param subject * The subject of the message * @param message * The email message */ public static void sendEmail(@Nonnull Context context, @Nullable String chooserMessage, @Nonnull String[] recipients, @Nullable String subject, @Nullable String message) { final Intent emailIntent = new Intent( android.content.Intent.ACTION_SEND); emailIntent .putExtra(android.content.Intent.EXTRA_EMAIL, recipients); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject); emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message); emailIntent.setType("plain/text"); final Intent intent = Intent.createChooser(emailIntent, chooserMessage); if (!(context instanceof Activity)) { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } context.startActivity(intent); } }