Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.content.Intent;
import android.net.Uri;
import android.os.Parcelable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import java.util.ArrayList;
import java.util.List;

public class Main {
    @NonNull
    public static Intent sendEmail(@NonNull String[] to, @NonNull String subject, @NonNull String body,
            @Nullable List<Uri> attachments) {
        final Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
        intent.setType("message/rfc822");
        intent.putExtra(Intent.EXTRA_EMAIL, to);
        intent.putExtra(Intent.EXTRA_SUBJECT, subject);
        final ArrayList<CharSequence> extraText = new ArrayList<>(1);
        extraText.add(body);
        intent.putCharSequenceArrayListExtra(Intent.EXTRA_TEXT, extraText);
        if (attachments != null && !attachments.isEmpty()) {
            intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, new ArrayList<Parcelable>(attachments));
        }
        return intent;
    }
}