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

/**
 * Helper method for sharing an image./*from ww w .  j  a  v  a  2  s.c  om*/
 *
 * @param context   The image context.
 * @param imagePath The path of the image to be shared.
 */
static void shareImage(Context context, String imagePath) {
    // Create the share intent and start the share activity
    File imageFile = new File(imagePath);
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("image/*");
    Uri photoURI = FileProvider.getUriForFile(context, FILE_PROVIDER_AUTHORITY, imageFile);
    shareIntent.putExtra(Intent.EXTRA_STREAM, photoURI);
    context.startActivity(shareIntent);
}

From source file:Main.java

/** Launch an email intent if the device is capable.
 *
 * @param activity The parent activity (for context)
 * @param addr The address to email (not the full URI)
 * @param text The email body//from w  ww  .  j a va2s  . c  o  m
 */
public static void launchEmailIntent(final Activity activity, String addr, String text) {
    Log.i(LOG_TAG, "Launch email intent from " + activity.getLocalClassName());
    // create email intent
    Intent emailIntent = new Intent(Intent.ACTION_SEND);
    emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { addr });
    emailIntent.setType("text/plain");
    // make sure there is an activity which can handle the intent.
    PackageManager emailpackageManager = activity.getPackageManager();
    List<ResolveInfo> emailresolveInfos = emailpackageManager.queryIntentActivities(emailIntent, 0);
    if (emailresolveInfos.size() > 0) {
        activity.startActivity(emailIntent);
    }
}

From source file:Main.java

/**
 * Lancia la finestra per la selezione di un gestore per la condivisione di un messaggio
 * (twitter, facebook, ....).// w ww.  ja  v a  2  s.c  o m
 * 
 * @param context
 * @param dialogTitle - Titolo della finestra di dialog (Share...)
 * @param subject - Subject (della email o titolo di twitter)
 * @param text - Testo del messaggio
 */
public static void share(Context context, String dialogTitle, String subject, String text) {
    final Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    intent.putExtra(Intent.EXTRA_TEXT, text);
    context.startActivity(Intent.createChooser(intent, dialogTitle));
}

From source file:Main.java

public static void sendText(Context context, String text) {
    String mimeType = getMimeTypeForExtension("txt");

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.setType(mimeType);//  w w w.ja va2 s. com
    intent.putExtra(Intent.EXTRA_TEXT, text);

    context.startActivity(intent);
}

From source file:Main.java

/**
 * Intent chooser is customized to remove unwanted apps.
 * 1. FaceBook has bug where only links can be shared.
 * 2. Cannot share this type of content via Google Docs and Skype.
 *//*from w w w . ja  v a  2  s. co  m*/
public static void ShareResult(Context mContext, String mResult, String mTitle) {
    List<Intent> targetedShareIntents = new ArrayList<Intent>();
    Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    List<ResolveInfo> resInfo = mContext.getPackageManager().queryIntentActivities(shareIntent, 0);
    if (!resInfo.isEmpty()) {
        for (ResolveInfo resolveInfo : resInfo) {
            String packageName = resolveInfo.activityInfo.packageName;
            Intent targetedShareIntent = new Intent(android.content.Intent.ACTION_SEND);
            targetedShareIntent.setType("text/plain");
            targetedShareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, mTitle);
            targetedShareIntent.putExtra(android.content.Intent.EXTRA_TITLE, mTitle);
            targetedShareIntent.putExtra(android.content.Intent.EXTRA_TEXT, mResult);
            if (!packageName.toLowerCase().contains("com.facebook.katana")
                    && !packageName.toLowerCase().contains("com.google.android.apps.docs")
                    && !packageName.toLowerCase().contains("com.skype.raider")) {
                targetedShareIntent.setPackage(packageName);
                targetedShareIntents.add(targetedShareIntent);
            }
        }
        Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), "Send your result");
        chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[] {}));
        mContext.startActivity(chooserIntent);
    }
    return;
}

From source file:Main.java

public static Intent share(String text, String mimeType, Uri... attachments) {
    final Intent intent = new Intent();
    intent.setType(mimeType);//ww w .j av a2 s  .  c o 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

public static Intent share(String text, String mimeType, Uri... attachments) {
    final Intent intent = new Intent();
    intent.setType(mimeType);//  w  w  w .  ja  v a  2  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:com.manning.androidhacks.hack004.util.LaunchEmailUtil.java

public static void launchEmailToIntent(Context context) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("message/rfc822");
    intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "feed@back.com" });
    intent.putExtra(Intent.EXTRA_SUBJECT, "[50AH] Feedback");
    intent.putExtra(Intent.EXTRA_TEXT, "Feedback:\n");
    context.startActivity(Intent.createChooser(intent, "Send feedback"));
}

From source file:com.manning.androidhacks.hack036.util.LaunchEmailUtil.java

public static void launchEmailToIntent(Context context) {
    Intent msg = new Intent(Intent.ACTION_SEND);

    StringBuilder body = new StringBuilder("\n\n----------\n");
    body.append(EnvironmentInfoUtil.getApplicationInfo(context));

    msg.putExtra(Intent.EXTRA_EMAIL, context.getString(R.string.mail_support_feedback_to).split(", "));
    msg.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.mail_support_feedback_subject));
    msg.putExtra(Intent.EXTRA_TEXT, body.toString());

    msg.setType("message/rfc822");
    context.startActivity(Intent.createChooser(msg, context.getString(R.string.pref_sendemail_title)));
}

From source file:com.contentecontent.cordova.plugins.share.Share.java

private void doSendIntent(String subject, String text, String imagePath, String mimeType) {
    Uri parsedUri = Uri.parse(imagePath);
    Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
    sendIntent.setType(mimeType);/*from w  w w .  j  ava2  s .c om*/
    sendIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
    sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, text);
    sendIntent.putExtra(android.content.Intent.EXTRA_STREAM, parsedUri);
    this.cordova.startActivityForResult(this, sendIntent, 0);
}