Example usage for android.content Intent ACTION_SEND_MULTIPLE

List of usage examples for android.content Intent ACTION_SEND_MULTIPLE

Introduction

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

Prototype

String ACTION_SEND_MULTIPLE

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

Click Source Link

Document

Activity Action: Deliver multiple data to someone else.

Usage

From source file:com.tct.mail.compose.ComposeActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    final boolean superCreated = super.onCreateOptionsMenu(menu);
    // Don't render any menu items when there are no accounts.
    if (mAccounts == null || mAccounts.length == 0) {
        return superCreated;
    }/*from  ww  w  . ja v  a  2s.c  o m*/
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.compose_menu, menu);

    /*
     * Start save in the correct enabled state.
     * 1) If a user launches compose from within gmail, save is disabled
     * until they add something, at which point, save is enabled, auto save
     * on exit; if the user empties everything, save is disabled, exiting does not
     * auto-save
     * 2) if a user replies/ reply all/ forwards from within gmail, save is
     * disabled until they change something, at which point, save is
     * enabled, auto save on exit; if the user empties everything, save is
     * disabled, exiting does not auto-save.
     * 3) If a user launches compose from another application and something
     * gets populated (attachments, recipients, body, subject, etc), save is
     * enabled, auto save on exit; if the user empties everything, save is
     * disabled, exiting does not auto-save
     */
    mSave = menu.findItem(R.id.save);
    String action = getIntent() != null ? getIntent().getAction() : null;
    boolean fromWidget = getIntent() != null && getIntent().getBooleanExtra(EXTRA_FROM_EMAIL_WIDGET, false);//TS: zheng.zou 2015-12-09 EMAIL BUGFIX_1059178 ADD
    enableSave(mInnerSavedState != null ? mInnerSavedState.getBoolean(EXTRA_SAVE_ENABLED)
            : ((Intent.ACTION_SEND.equals(action) && !fromWidget) //TS: zheng.zou 2015-12-09 EMAIL BUGFIX_1059178 MOD
                    || Intent.ACTION_SEND_MULTIPLE.equals(action) || Intent.ACTION_SENDTO.equals(action)
                    || shouldSave()));

    final MenuItem helpItem = menu.findItem(R.id.help_info_menu_item);
    final MenuItem sendFeedbackItem = menu.findItem(R.id.feedback_menu_item);
    //TS: Gantao 2015-7-13 EMAIL FEATURE_1033148 DEL_S
    //For feature:long click the attachment icon menu can show the menu discription,
    //we should remove its useless sub menu.
    //        final MenuItem attachFromServiceItem = menu.findItem(R.id.attach_from_service_stub1);
    //TS: Gantao 2015-7-13 EMAIL FEATURE_1033148 DEL_E
    //[FEATURE]-Add-BEGIN by TSCD.chao zhang,04/17/2014,FR 631895(porting from FR514398)
    MenuItem priority = menu.findItem(R.id.priority);
    if (priority != null) {
        // TS: xiaolin.li 2014-11-25 EMAIL READ_PLF MOD_S
        //priority.setVisible(getResources().getBoolean(R.bool.feature_email_priority_on));
        priority.setVisible(PLFUtils.getBoolean(this, "feature_email_priority_on"));
        // TS: xiaolin.li 2014-11-25 EMAIL READ_PLF MOD_E
    }
    //[FEATURE]-Add-END by TSCD.chao zhang
    if (helpItem != null) {
        helpItem.setVisible(mAccount != null && mAccount.supportsCapability(AccountCapabilities.HELP_CONTENT));
    }
    if (sendFeedbackItem != null) {
        sendFeedbackItem
                .setVisible(mAccount != null && mAccount.supportsCapability(AccountCapabilities.SEND_FEEDBACK));
    }
    //TS: Gantao 2015-7-13 EMAIL FEATURE_1033148 DEL_S
    //For feature:long click the attachment icon menu can show the menu discription,
    //we should remove its useless sub menu.
    //        if (attachFromServiceItem != null) {
    //            attachFromServiceItem.setVisible(shouldEnableAttachFromServiceMenu(mAccount));
    //        }
    //TS: Gantao 2015-7-13 EMAIL FEATURE_1033148 DEL_E

    //TS: yanhua.chen 2015-4-30 EMAIL BUGFIX_989399 MOD_S
    // Show attach picture on pre-K devices.
    //menu.findItem(R.id.add_photo_attachment).setVisible(!Utils.isRunningKitkatOrLater());
    //TS: yanhua.chen 2015-4-30 EMAIL BUGFIX_989399 MOD_E

    // TS: Gantao 2015-10-30 EMAIL FEATURE_1104470 ADD_S
    MenuItem saveGroupItem = menu.findItem(R.id.group);
    if (saveGroupItem != null) {
        saveGroupItem.setVisible(PLFUtils.getBoolean(this, "feature_email_save_group"));
    }
    // TS: Gantao 2015-10-30 EMAIL FEATURE_1104470 ADD_E

    return true;
}

From source file:com.codename1.impl.android.AndroidImplementation.java

/**
 * @inheritDoc//  w  w w  .  ja  v  a2  s . c o m
 */
public void sendMessage(String[] recipients, String subject, Message msg) {
    if (editInProgress()) {
        stopEditing(true);
    }
    Intent emailIntent;
    String attachment = msg.getAttachment();
    boolean hasAttachment = (attachment != null && attachment.length() > 0) || msg.getAttachments().size() > 0;

    if (msg.getMimeType().equals(Message.MIME_TEXT) && !hasAttachment) {
        StringBuilder to = new StringBuilder();
        for (int i = 0; i < recipients.length; i++) {
            to.append(recipients[i]);
            to.append(";");
        }
        emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:" + to.toString() + "?subject="
                + Uri.encode(subject) + "&body=" + Uri.encode(msg.getContent())));
    } else {
        if (hasAttachment) {
            if (msg.getAttachments().size() > 1) {
                emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
                emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
                emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
                emailIntent.setType(msg.getMimeType());
                ArrayList<Uri> uris = new ArrayList<Uri>();

                for (String path : msg.getAttachments().keySet()) {
                    uris.add(Uri.parse(fixAttachmentPath(path)));
                }

                emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
            } else {
                emailIntent = new Intent(android.content.Intent.ACTION_SEND);
                emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
                emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
                emailIntent.setType(msg.getMimeType());
                emailIntent.setType(msg.getAttachmentMimeType());
                //if the attachment is in the uder home dir we need to copy it
                //to an accessible dir
                attachment = fixAttachmentPath(attachment);
                emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(attachment));
            }
        } else {
            emailIntent = new Intent(android.content.Intent.ACTION_SEND);
            emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
            emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
            emailIntent.setType(msg.getMimeType());
        }
        if (msg.getMimeType().equals(Message.MIME_HTML)) {
            emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(msg.getContent()));
        } else {
            /*
            // Attempted this workaround to fix the ClassCastException that occurs on android when
            // there are multiple attachments.  Unfortunately, this fixes the stack trace, but
            // has the unwanted side-effect of producing a blank message body.
            // Same workaround for HTML mimetype also fails the same way.
            // Conclusion, Just live with the stack trace.  It doesn't seem to affect the
            // execution of the program... treat it as a warning.
            // See https://github.com/codenameone/CodenameOne/issues/1782
            if (msg.getAttachments().size() > 1) {
            ArrayList<String> contentArr = new ArrayList<String>();
            contentArr.add(msg.getContent());
            emailIntent.putStringArrayListExtra(android.content.Intent.EXTRA_TEXT, contentArr);
            } else {
            emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, msg.getContent());
                    
            }*/
            emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, msg.getContent());
        }

    }
    final String attach = attachment;
    AndroidNativeUtil.startActivityForResult(Intent.createChooser(emailIntent, "Send mail..."),
            new IntentResultListener() {

                @Override
                public void onActivityResult(int requestCode, int resultCode, Intent data) {
                    if (attach != null && attach.length() > 0 && attach.contains("tmp")) {
                        FileSystemStorage.getInstance().delete(attach);
                    }
                }
            });
}

From source file:com.zoffcc.applications.zanavi.Navit.java

void sendEmailWithAttachment(Context c, final String recipient, final String subject, final String message,
        final String full_file_name, final String full_file_name_suppl) {
    try {/*ww  w  . j  av a  2 s  .  c  om*/
        Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", recipient, null));
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
        ArrayList<Uri> uris = new ArrayList<>();
        uris.add(Uri.parse("file://" + full_file_name));
        try {
            if (new File(full_file_name_suppl).length() > 0) {
                uris.add(Uri.parse("file://" + full_file_name_suppl));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        List<ResolveInfo> resolveInfos = getPackageManager().queryIntentActivities(emailIntent, 0);
        List<LabeledIntent> intents = new ArrayList<>();

        if (resolveInfos.size() != 0) {
            for (ResolveInfo info : resolveInfos) {
                Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
                System.out.println(
                        "email:" + "comp=" + info.activityInfo.packageName + " " + info.activityInfo.name);
                intent.setComponent(new ComponentName(info.activityInfo.packageName, info.activityInfo.name));
                intent.putExtra(Intent.EXTRA_EMAIL, new String[] { recipient });
                if (subject != null)
                    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
                if (message != null)
                    intent.putExtra(Intent.EXTRA_TEXT, message);
                intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
                intents.add(new LabeledIntent(intent, info.activityInfo.packageName,
                        info.loadLabel(getPackageManager()), info.icon));
            }
            Intent chooser = Intent.createChooser(intents.remove(intents.size() - 1),
                    Navit.get_text("Send email with attachments"));
            chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, intents.toArray(new LabeledIntent[intents.size()]));
            startActivity(chooser);
        } else {
            System.out.println("email:" + "No Email App found");
            new AlertDialog.Builder(c).setMessage(Navit.get_text("No Email App found"))
                    .setPositiveButton(Navit.get_text("Ok"), null).show();
        }

        //         final Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", recipient, null));
        //         if (recipient != null) emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { recipient });
        //         if (subject != null) emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
        //         if (message != null) emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
        //         if (full_file_name != null)
        //         {
        //            emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + full_file_name));
        //            //ArrayList<Uri> uris = new ArrayList<>();
        //            //uris.add(Uri.parse("file://" + full_file_name));
        //            //emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); //ArrayList<Uri> of attachment Uri's
        //         }
        //
        //         List<ResolveInfo> resolveInfos = getPackageManager().queryIntentActivities(emailIntent, 0);
        //         if (resolveInfos.size() != 0)
        //         {
        //            String packageName = resolveInfos.get(0).activityInfo.packageName;
        //            String name = resolveInfos.get(0).activityInfo.name;
        //
        //            emailIntent.setAction(Intent.ACTION_SEND);
        //            emailIntent.setComponent(new ComponentName(packageName, name));
        //
        //            System.out.println("email:" + "comp=" + packageName + " " + name);
        //
        //            startActivity(emailIntent);
        //         }
        //         else
        //         {
        //            System.out.println("email:" + "No Email App found");
        //            new AlertDialog.Builder(c).setMessage(Navit.get_text("No Email App found")).setPositiveButton(Navit.get_text("Ok"), null).show();
        //         }

    } catch (ActivityNotFoundException e) {
        // cannot send email for some reason
    }
}