Example usage for android.content Intent putCharSequenceArrayListExtra

List of usage examples for android.content Intent putCharSequenceArrayListExtra

Introduction

In this page you can find the example usage for android.content Intent putCharSequenceArrayListExtra.

Prototype

public @NonNull Intent putCharSequenceArrayListExtra(String name, ArrayList<CharSequence> value) 

Source Link

Document

Add extended data to the intent.

Usage

From source file:Main.java

public static Intent share(String text, String mimeType, Uri... attachments) {
    final Intent intent = new Intent();
    intent.setType(mimeType);//from  w  ww .j av  a2  s.  c om
    if (attachments.length > 1) {
        intent.setAction(Intent.ACTION_SEND_MULTIPLE);
        final ArrayList<CharSequence> textExtra = new ArrayList<>();
        textExtra.add(text);
        intent.putCharSequenceArrayListExtra(Intent.EXTRA_TEXT, textExtra);
        final ArrayList<Parcelable> uris = new ArrayList<>();
        Collections.addAll(uris, attachments);
        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
    } else {
        intent.setAction(Intent.ACTION_SEND);
        intent.putExtra(Intent.EXTRA_TEXT, text);
        intent.putExtra(Intent.EXTRA_STREAM, attachments[0]);
    }
    return intent;
}

From source file:Main.java

public static Intent share(String text, String mimeType, Uri... attachments) {
    final Intent intent = new Intent();
    intent.setType(mimeType);//from ww  w.  ja v a2  s  . co m
    if (attachments.length > 1) {
        intent.setAction(Intent.ACTION_SEND_MULTIPLE);
        final ArrayList<CharSequence> textExtra = new ArrayList<>();
        textExtra.add(text);
        intent.putCharSequenceArrayListExtra(Intent.EXTRA_TEXT, textExtra);
        final ArrayList<Parcelable> uris = new ArrayList<>();
        Collections.addAll(uris, attachments);
        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
    } else {
        intent.setAction(Intent.ACTION_SEND);
        intent.putExtra(Intent.EXTRA_TEXT, text);
        if (attachments.length > 0) {
            intent.putExtra(Intent.EXTRA_STREAM, attachments[0]);
        }
    }
    return intent;
}

From source file:Main.java

@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);/*  w  w  w. j a  v  a2s  .co  m*/
    intent.putCharSequenceArrayListExtra(Intent.EXTRA_TEXT, extraText);
    if (attachments != null && !attachments.isEmpty()) {
        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, new ArrayList<Parcelable>(attachments));
    }
    return intent;
}