Example usage for android.content Intent ACTION_SEND

List of usage examples for android.content Intent ACTION_SEND

Introduction

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

Prototype

String ACTION_SEND

To view the source code for android.content Intent ACTION_SEND.

Click Source Link

Document

Activity Action: Deliver some data to someone else.

Usage

From source file:Main.java

public static void shareAppInfo(Context context, String info) {
    if (!TextUtils.isEmpty(info)) {
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_TEXT, info);
        context.startActivity(intent);//  w w w  .j av  a 2  s . c o  m
    }
}

From source file:Main.java

public static void share(Context context, String imageFileLocation, String textToSend) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("image/*");

    intent.putExtra(Intent.EXTRA_TEXT, textToSend);
    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(imageFileLocation)));

    context.startActivity(Intent.createChooser(intent, "Share with..."));
}

From source file:Main.java

public static void sendEmail(Context context, String receiver, String subject, String body) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("message/rfc822");
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | IntentCompat.FLAG_ACTIVITY_CLEAR_TASK
            | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    intent.putExtra(Intent.EXTRA_EMAIL, new String[] { receiver });
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    try {/*from www . j  av a 2s.  c  o m*/
        context.startActivity(Intent.createChooser(intent, "Send mail..."));
    } catch (android.content.ActivityNotFoundException ex) {
    }
}

From source file:Main.java

public static void startShareIntentActivity(Activity activity, String text) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_TEXT, text);
    activity.startActivity(intent);/*from w w  w.  j  a  v a 2 s .c o m*/
}

From source file:Main.java

/**
 * Share App/*from  w  ww.java2s.  c o  m*/
 *
 * @param context
 */
public static void shareApp(Context context) {
    Intent intent = new Intent(android.content.Intent.ACTION_SEND);
    intent.setType("text/plain");
    String title = "Share NavigationFastFrame";
    String extraText = "NavigationFastFrame is a very good Frame.";
    intent.putExtra(Intent.EXTRA_TEXT, extraText); //Share text.
    intent.putExtra(Intent.EXTRA_SUBJECT, title);
    context.startActivity(Intent.createChooser(intent, "Share this"));
}

From source file:Main.java

public static void shareFile(Context context, String title, String subject, String text, String mime,
        String path) {//from  w w w.  j  ava 2 s.com
    Intent sendIntent = new Intent(Intent.ACTION_SEND);
    sendIntent.setType(mime);
    sendIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
    sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + path));
    sendIntent.putExtra(Intent.EXTRA_TEXT, text);
    context.startActivity(Intent.createChooser(sendIntent, title));
}

From source file:Main.java

public static void shareViaIntent(Context context, String subject, String extraText) {
    Intent sendIntent = new Intent();
    sendIntent.setType("text/plain");
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
    sendIntent.putExtra(Intent.EXTRA_TEXT, extraText);
    context.startActivity(sendIntent);//  w  w  w . ja va 2  s.  c  om
}

From source file:Main.java

public static void sendMail(Context context, String[] mail, String subject, String body) {
    Intent i = new Intent(Intent.ACTION_SEND);
    i.setType("message/rfc822");
    //        i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"recipient@example.com"});
    //        i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
    //        i.putExtra(Intent.EXTRA_TEXT   , "body of email");
    i.putExtra(Intent.EXTRA_EMAIL, mail);
    i.putExtra(Intent.EXTRA_SUBJECT, subject);
    i.putExtra(Intent.EXTRA_TEXT, body);
    try {/*  w  w w.java2s  .co m*/
        context.startActivity(Intent.createChooser(i, "Send mail..."));
    } catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(context, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
    }
}

From source file:Main.java

public static void sharePic(Uri uri, String desc, Context context) {

    Intent shareIntent = new Intent();
    shareIntent.setAction(Intent.ACTION_SEND);
    shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
    shareIntent.setType("image/jpeg");
    context.startActivity(Intent.createChooser(shareIntent, desc));
}

From source file:Main.java

public static void mail(Activity activity, String email, String subject, String content) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");

    intent.putExtra(Intent.EXTRA_EMAIL, new String[] { email });
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);

    if (content != null) {
        intent.putExtra(Intent.EXTRA_TEXT, content);
    }/* www.ja v  a  2s.co m*/

    final PackageManager manager = activity.getPackageManager();
    final List<ResolveInfo> matches = manager.queryIntentActivities(intent, 0);

    for (ResolveInfo info : matches) {
        if (info.activityInfo.packageName.endsWith(".gm")
                || info.activityInfo.name.toLowerCase().contains("gmail")) {
            intent.setClassName(info.activityInfo.packageName, info.activityInfo.name);
        } else if (info.activityInfo.packageName.endsWith(".email")
                || info.activityInfo.name.toLowerCase().contains("email")) {
            intent.setClassName(info.activityInfo.packageName, info.activityInfo.name);
        }
    }

    activity.startActivity(intent);
}