share Text via Email Intent - Android android.content

Android examples for android.content:Intent

Description

share Text via Email Intent

Demo Code

import android.app.Activity;
import android.content.Intent;
import android.widget.Toast;

public class Main {

  public static void shareText(Activity activity, String subject, String text, int chooserTitleID) {
    Intent i = new Intent(Intent.ACTION_SEND);
    i.setType("text/plain");
    i.putExtra(Intent.EXTRA_EMAIL, "");
    i.putExtra(Intent.EXTRA_SUBJECT, subject);
    i.putExtra(Intent.EXTRA_TEXT, text);
    try {//w  w  w.j  a  v  a 2 s .c  o  m
      activity.startActivity(Intent.createChooser(i, activity.getString(chooserTitleID)));
    } catch (android.content.ActivityNotFoundException ex) {
      Toast.makeText(activity, "Unable to find app", Toast.LENGTH_SHORT).show();
    }

  }

}

Related Tutorials