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.asksven.betterbatterystats.StatsActivity.java

public Dialog getShareDialog() {

    final ArrayList<Integer> selectedSaveActions = new ArrayList<Integer>();

    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    boolean saveDumpfile = sharedPrefs.getBoolean("save_dumpfile", true);
    boolean saveLogcat = sharedPrefs.getBoolean("save_logcat", false);
    boolean saveDmesg = sharedPrefs.getBoolean("save_dmesg", false);

    if (saveDumpfile) {
        selectedSaveActions.add(0);//  w  w w . j  a v a2s .co  m
    }
    if (saveLogcat) {
        selectedSaveActions.add(1);
    }
    if (saveDmesg) {
        selectedSaveActions.add(2);
    }

    //----
    LinearLayout layout = new LinearLayout(this);
    LinearLayout.LayoutParams parms = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.setLayoutParams(parms);

    layout.setGravity(Gravity.CLIP_VERTICAL);
    layout.setPadding(2, 2, 2, 2);

    final TextView editTitle = new TextView(StatsActivity.this);
    editTitle.setText(R.string.share_dialog_edit_title);
    editTitle.setPadding(40, 40, 40, 40);
    editTitle.setGravity(Gravity.LEFT);
    editTitle.setTextSize(20);

    final EditText editDescription = new EditText(StatsActivity.this);

    LinearLayout.LayoutParams tv1Params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    tv1Params.bottomMargin = 5;
    layout.addView(editTitle, tv1Params);
    layout.addView(editDescription, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));

    //----

    // Set the dialog title
    builder.setTitle(R.string.title_share_dialog)
            .setMultiChoiceItems(R.array.saveAsLabels, new boolean[] { saveDumpfile, saveLogcat, saveDmesg },
                    new DialogInterface.OnMultiChoiceClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                            if (isChecked) {
                                // If the user checked the item, add it to the
                                // selected items
                                selectedSaveActions.add(which);
                            } else if (selectedSaveActions.contains(which)) {
                                // Else, if the item is already in the array,
                                // remove it
                                selectedSaveActions.remove(Integer.valueOf(which));
                            }
                        }
                    })
            .setView(layout)
            // Set the action buttons
            .setPositiveButton(R.string.label_button_share, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    ArrayList<Uri> attachements = new ArrayList<Uri>();

                    Reference myReferenceFrom = ReferenceStore.getReferenceByName(m_refFromName,
                            StatsActivity.this);
                    Reference myReferenceTo = ReferenceStore.getReferenceByName(m_refToName,
                            StatsActivity.this);

                    Reading reading = new Reading(StatsActivity.this, myReferenceFrom, myReferenceTo);

                    // save as text is selected
                    if (selectedSaveActions.contains(0)) {
                        attachements.add(reading.writeDumpfile(StatsActivity.this,
                                editDescription.getText().toString()));
                    }
                    // save logcat if selected
                    if (selectedSaveActions.contains(1)) {
                        attachements.add(StatsProvider.getInstance().writeLogcatToFile());
                    }
                    // save dmesg if selected
                    if (selectedSaveActions.contains(2)) {
                        attachements.add(StatsProvider.getInstance().writeDmesgToFile());
                    }

                    if (!attachements.isEmpty()) {
                        Intent shareIntent = new Intent();
                        shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
                        shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachements);
                        shareIntent.setType("text/*");
                        startActivity(Intent.createChooser(shareIntent, "Share info to.."));
                    }
                }
            }).setNeutralButton(R.string.label_button_save, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {

                    try {
                        Reference myReferenceFrom = ReferenceStore.getReferenceByName(m_refFromName,
                                StatsActivity.this);
                        Reference myReferenceTo = ReferenceStore.getReferenceByName(m_refToName,
                                StatsActivity.this);

                        Reading reading = new Reading(StatsActivity.this, myReferenceFrom, myReferenceTo);

                        // save as text is selected
                        if (selectedSaveActions.contains(0)) {
                            reading.writeDumpfile(StatsActivity.this, editDescription.getText().toString());
                        }
                        // save logcat if selected
                        if (selectedSaveActions.contains(1)) {
                            StatsProvider.getInstance().writeLogcatToFile();
                        }
                        // save dmesg if selected
                        if (selectedSaveActions.contains(2)) {
                            StatsProvider.getInstance().writeDmesgToFile();
                        }

                        Snackbar.make(findViewById(android.R.id.content), getString(R.string.info_files_written)
                                + ": " + StatsProvider.getWritableFilePath(), Snackbar.LENGTH_LONG).show();
                    } catch (Exception e) {
                        Log.e(TAG, "an error occured writing files: " + e.getMessage());
                        Snackbar.make(findViewById(android.R.id.content), R.string.info_files_write_error,
                                Snackbar.LENGTH_LONG).show();
                    }

                }
            }).setNegativeButton(R.string.label_button_cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    // do nothing
                }
            });

    return builder.create();
}

From source file:org.getlantern.firetweet.activity.support.ComposeActivity.java

private boolean setComposeTitle(final Intent intent) {
    final String action = intent.getAction();
    if (INTENT_ACTION_REPLY.equals(action)) {
        if (mInReplyToStatus == null)
            return false;
        final String display_name = UserColorNameUtils.getDisplayName(this, mInReplyToStatus.user_id,
                mInReplyToStatus.user_name, mInReplyToStatus.user_screen_name);
        setTitle(getString(R.string.reply_to, display_name));
    } else if (INTENT_ACTION_QUOTE.equals(action)) {
        if (mInReplyToStatus == null)
            return false;
        final String display_name = UserColorNameUtils.getDisplayName(this, mInReplyToStatus.user_id,
                mInReplyToStatus.user_name, mInReplyToStatus.user_screen_name);
        setTitle(getString(R.string.quote_user, display_name));
        //            mSubtitleView.setVisibility(mInReplyToStatus.user_is_protected
        //                    && mInReplyToStatus.account_id != mInReplyToStatus.user_id ? View.VISIBLE : View.GONE);
    } else if (INTENT_ACTION_EDIT_DRAFT.equals(action)) {
        if (mDraftItem == null)
            return false;
        setTitle(R.string.edit_draft);//from ww  w .ja  v a2 s . c  om
    } else if (INTENT_ACTION_MENTION.equals(action)) {
        if (mMentionUser == null)
            return false;
        final String display_name = UserColorNameUtils.getDisplayName(this, mMentionUser.id, mMentionUser.name,
                mMentionUser.screen_name);
        setTitle(getString(R.string.mention_user, display_name));
    } else if (INTENT_ACTION_REPLY_MULTIPLE.equals(action)) {
        setTitle(R.string.reply);
    } else if (Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action)) {
        setTitle(R.string.share);
    } else {
        setTitle(R.string.compose);
    }
    return true;
}

From source file:org.mariotaku.twidere.activity.support.ComposeActivity.java

private boolean setComposeTitle(final Intent intent) {
    final String action = intent.getAction();
    final UserColorNameManager manager = UserColorNameManager.getInstance(this);
    final boolean nameFirst = mPreferences.getBoolean(KEY_NAME_FIRST);
    if (INTENT_ACTION_REPLY.equals(action)) {
        if (mInReplyToStatus == null)
            return false;
        final String displayName = manager.getDisplayName(mInReplyToStatus.user_id, mInReplyToStatus.user_name,
                mInReplyToStatus.user_screen_name, nameFirst, false);
        setTitle(getString(R.string.reply_to, displayName));
    } else if (INTENT_ACTION_QUOTE.equals(action)) {
        if (mInReplyToStatus == null)
            return false;
        final String displayName = manager.getDisplayName(mInReplyToStatus.user_id, mInReplyToStatus.user_name,
                mInReplyToStatus.user_screen_name, nameFirst, false);
        setTitle(getString(R.string.quote_user, displayName));
    } else if (INTENT_ACTION_EDIT_DRAFT.equals(action)) {
        if (mDraftItem == null)
            return false;
        setTitle(R.string.edit_draft);//from   ww  w.  jav a2s .  c  o  m
    } else if (INTENT_ACTION_MENTION.equals(action)) {
        if (mMentionUser == null)
            return false;
        final String displayName = manager.getDisplayName(mMentionUser.id, mMentionUser.name,
                mMentionUser.screen_name, nameFirst, false);
        setTitle(getString(R.string.mention_user, displayName));
    } else if (INTENT_ACTION_REPLY_MULTIPLE.equals(action)) {
        setTitle(R.string.reply);
    } else if (Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action)) {
        setTitle(R.string.share);
    } else {
        setTitle(R.string.compose);
    }
    return true;
}

From source file:de.azapps.mirakel.main_activity.MainActivity.java

private void handleIntent(final Intent intent) {
    if ((intent == null) || (intent.getAction() == null)) {
        Log.d(MainActivity.TAG, "action null");
    } else if (DefinitionsHelper.SHOW_TASK.equals(intent.getAction())
            || DefinitionsHelper.SHOW_TASK_REMINDER.equals(intent.getAction())
            || DefinitionsHelper.SHOW_TASK_FROM_WIDGET.equals(intent.getAction())) {
        final Optional<Task> task = TaskHelper.getTaskFromIntent(intent);
        if (task.isPresent()) {
            this.currentList = task.get().getList();
            if (this.mDrawerLayout != null) {
                this.mDrawerLayout.postDelayed(new Runnable() {
                    @Override/*from www. ja  v  a  2s  . c om*/
                    public void run() {
                        setCurrentTask(task.get(), true);
                    }
                }, 10L);
            }
        } else {
            Log.d(MainActivity.TAG, "task null");
        }
        if (intent.getAction().equals(DefinitionsHelper.SHOW_TASK_FROM_WIDGET)) {
            this.closeOnBack = true;
        }
    } else if (intent.getAction().equals(Intent.ACTION_SEND)
            || intent.getAction().equals(Intent.ACTION_SEND_MULTIPLE)) {
        this.closeOnBack = true;
        this.newTaskContent = intent.getStringExtra(Intent.EXTRA_TEXT);
        this.newTaskSubject = intent.getStringExtra(Intent.EXTRA_SUBJECT);
        // If from google now, the content is the subject
        if ((intent.getCategories() != null)
                && intent.getCategories().contains("com.google.android.voicesearch.SELF_NOTE")
                && !this.newTaskContent.isEmpty()) {
            this.newTaskSubject = this.newTaskContent;
            this.newTaskContent = "";
        }
        if (!"text/plain".equals(intent.getType()) && (this.newTaskSubject == null)) {
            this.newTaskSubject = MirakelCommonPreferences.getImportFileTitle();
        }
        final Optional<ListMirakel> listFromSharing = MirakelModelPreferences.getImportDefaultList();
        if (listFromSharing.isPresent()) {
            addTaskFromSharing(listFromSharing.get(), intent);
        } else {
            final AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle(R.string.import_to);
            final List<CharSequence> items = new ArrayList<>();
            final List<Long> list_ids = new ArrayList<>();
            final int currentItem = 0;
            for (final ListMirakel list : ListMirakel.all()) {
                if (list.getId() > 0) {
                    items.add(list.getName());
                    list_ids.add(list.getId());
                }
            }
            builder.setSingleChoiceItems(items.toArray(new CharSequence[items.size()]), currentItem,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(final DialogInterface dialog, final int which) {
                            final Optional<ListMirakel> listMirakelOptional = ListMirakel
                                    .get(list_ids.get(which));
                            withOptional(listMirakelOptional, new OptionalUtils.Procedure<ListMirakel>() {
                                @Override
                                public void apply(final ListMirakel input) {
                                    addTaskFromSharing(input, intent);
                                    dialog.dismiss();
                                }
                            });
                        }
                    });
            builder.create().show();
        }
    } else if (intent.getAction().equals(DefinitionsHelper.SHOW_LIST)
            || intent.getAction().contains(DefinitionsHelper.SHOW_LIST_FROM_WIDGET)) {
        final Optional<ListMirakel> listMirakelOptional = ListHelper.getListMirakelFromIntent(intent);
        if (listMirakelOptional.isPresent()) {
            final ListMirakel list = listMirakelOptional.get();
            setCurrentList(list);
            final Optional<Task> taskOptional = list.getFirstTask();
            if (taskOptional.isPresent()) {
                this.currentTask = taskOptional.get();
            }
            if (getTaskFragment() != null) {
                getTaskFragment().update(this.currentTask);
            }
        } else {
            Log.d(TAG, "show_list does not pass list, so ignore this");
        }
    } else if (intent.getAction().equals(DefinitionsHelper.SHOW_LISTS)) {
        this.mDrawerLayout.openDrawer(DefinitionsHelper.GRAVITY_LEFT);
    } else if (intent.getAction().equals(Intent.ACTION_SEARCH)) {
        final String query = intent.getStringExtra(SearchManager.QUERY);
        search(query);
    } else if (intent.getAction().contains(DefinitionsHelper.ADD_TASK_FROM_WIDGET)) {
        final int listId = Integer
                .parseInt(intent.getAction().replace(DefinitionsHelper.ADD_TASK_FROM_WIDGET, ""));
        final Optional<ListMirakel> listMirakelOptional = ListMirakel.get(listId);
        if (listMirakelOptional.isPresent()) {
            setCurrentList(listMirakelOptional.get());
        } else {
            setCurrentList(ListMirakel.safeFirst());
        }
        this.mDrawerLayout.postDelayed(new Runnable() {
            @Override
            public void run() {
                if ((getTasksFragment() != null) && getTasksFragment().isReady()) {
                    getTasksFragment().focusNew(true);
                } else if (!MirakelCommonPreferences.isTablet()) {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            if (getTasksFragment() != null) {
                                getTasksFragment().focusNew(true);
                            } else {
                                Log.wtf(MainActivity.TAG, "Tasksfragment null");
                            }
                        }
                    });
                }
            }
        }, 10);
    } else if (intent.getAction().equals(DefinitionsHelper.SHOW_MESSAGE)) {
        final String message = intent.getStringExtra(Intent.EXTRA_TEXT);
        String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT);
        if (message != null) {
            if (subject == null) {
                subject = getString(R.string.message_notification);
            }
            final TextView msg = (TextView) getLayoutInflater().inflate(R.layout.alertdialog_textview, null);
            msg.setText(Html.fromHtml(message));
            msg.setMovementMethod(LinkMovementMethod.getInstance());
            msg.setClickable(true);
            new AlertDialog.Builder(this).setTitle(subject).setView(msg).show();
        }
    } else {
        setCurrentItem(getTaskFragmentPosition());
    }
    if (((intent == null) || (intent.getAction() == null)
            || !intent.getAction().contains(DefinitionsHelper.ADD_TASK_FROM_WIDGET))
            && (getTasksFragment() != null)) {
        getTasksFragment().clearFocus();
    }
    setIntent(null);
    if (this.currentList == null) {
        setCurrentList(SpecialList.firstSpecialSafe());
    }
}

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

private void initAttachmentsFromIntent(Intent intent) {
    Bundle extras = intent.getExtras();/*from ww  w. java  2s  .co  m*/
    if (extras == null) {
        extras = Bundle.EMPTY;
    }
    final String action = intent.getAction();
    if (!mAttachmentsChanged) {
        long totalSize = 0;
        if (extras.containsKey(EXTRA_ATTACHMENTS)) {
            final String[] uris = (String[]) extras.getSerializable(EXTRA_ATTACHMENTS);
            final ArrayList<Uri> parsedUris = Lists.newArrayListWithCapacity(uris.length);
            for (String uri : uris) {
                parsedUris.add(Uri.parse(uri));
            }
            totalSize += handleAttachmentUrisFromIntent(parsedUris);
        }
        if (extras.containsKey(Intent.EXTRA_STREAM)) {
            if (Intent.ACTION_SEND_MULTIPLE.equals(action)) {
                final ArrayList<Uri> uris = extras.getParcelableArrayList(Intent.EXTRA_STREAM);
                totalSize += handleAttachmentUrisFromIntent(uris);
            } else {
                final Uri uri = extras.getParcelable(Intent.EXTRA_STREAM);
                final ArrayList<Uri> uris = Lists.newArrayList(uri);
                totalSize += handleAttachmentUrisFromIntent(uris);
            }
        }

        if (totalSize > 0) {
            mAttachmentsChanged = true;
            updateSaveUi();

            Analytics.getInstance().sendEvent("send_intent_with_attachments",
                    Integer.toString(getAttachments().size()), null, totalSize);
        }
    }
}

From source file:com.android.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  w  w w.j a 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;
    enableSave(mInnerSavedState != null ? mInnerSavedState.getBoolean(EXTRA_SAVE_ENABLED)
            : (Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action)
                    || Intent.ACTION_SENDTO.equals(action) || isDraftDirty()));

    final MenuItem helpItem = menu.findItem(R.id.help_info_menu_item);
    final MenuItem sendFeedbackItem = menu.findItem(R.id.feedback_menu_item);
    final MenuItem attachFromServiceItem = menu.findItem(R.id.attach_from_service_stub1);
    if (helpItem != null) {
        helpItem.setVisible(mAccount != null && mAccount.supportsCapability(AccountCapabilities.HELP_CONTENT));
    }
    if (sendFeedbackItem != null) {
        sendFeedbackItem
                .setVisible(mAccount != null && mAccount.supportsCapability(AccountCapabilities.SEND_FEEDBACK));
    }
    if (attachFromServiceItem != null) {
        attachFromServiceItem.setVisible(shouldEnableAttachFromServiceMenu(mAccount));
    }

    // Show attach picture on pre-K devices.
    menu.findItem(R.id.add_photo_attachment).setVisible(!Utils.isRunningKitkatOrLater());

    return true;
}

From source file:com.android.mms.ui.ComposeMessageActivity.java

private boolean handleSendIntent() {
    Intent intent = getIntent();/*  www .  ja  va2s  .  c  o m*/
    Bundle extras = intent.getExtras();
    if (extras == null) {
        return false;
    }

    final String mimeType = intent.getType();
    String action = intent.getAction();
    if (Intent.ACTION_SEND.equals(action)) {
        if (extras.containsKey(Intent.EXTRA_STREAM)) {
            final Uri uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);
            getAsyncDialog().runAsync(new Runnable() {
                @Override
                public void run() {
                    addAttachment(mimeType, uri, false);
                }
            }, null, R.string.adding_attachments_title);
            return true;
        } else if (extras.containsKey(Intent.EXTRA_TEXT)) {
            mWorkingMessage.setText(extras.getString(Intent.EXTRA_TEXT));
            return true;
        }
    } else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && extras.containsKey(Intent.EXTRA_STREAM)) {
        SlideshowModel slideShow = mWorkingMessage.getSlideshow();
        final ArrayList<Parcelable> uris = extras.getParcelableArrayList(Intent.EXTRA_STREAM);
        int currentSlideCount = slideShow != null ? slideShow.size() : 0;
        int importCount = uris.size();
        if (importCount + currentSlideCount > SlideshowEditor.MAX_SLIDE_NUM) {
            importCount = Math.min(SlideshowEditor.MAX_SLIDE_NUM - currentSlideCount, importCount);
            Toast.makeText(ComposeMessageActivity.this,
                    getString(R.string.too_many_attachments, SlideshowEditor.MAX_SLIDE_NUM, importCount),
                    Toast.LENGTH_LONG).show();
        }

        // Attach all the pictures/videos asynchronously off of the UI thread.
        // Show a progress dialog if adding all the slides hasn't finished
        // within half a second.
        final int numberToImport = importCount;
        getAsyncDialog().runAsync(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < numberToImport; i++) {
                    Parcelable uri = uris.get(i);
                    addAttachment(mimeType, (Uri) uri, true);
                }
            }
        }, null, R.string.adding_attachments_title);
        return true;
    }
    return false;
}

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

private void initAttachmentsFromIntent(Intent intent) {
    Bundle extras = intent.getExtras();//w  ww .  j a  v  a  2 s  . co m
    if (extras == null) {
        extras = Bundle.EMPTY;
    }
    final String action = intent.getAction();
    if (!mAttachmentsChanged) {
        long totalSize = 0;
        if (extras.containsKey(EXTRA_ATTACHMENTS)) {
            String[] uris = (String[]) extras.getSerializable(EXTRA_ATTACHMENTS);
            for (String uriString : uris) {
                final Uri uri = Uri.parse(uriString);
                long size = 0;
                try {
                    if (handleSpecialAttachmentUri(uri)) {
                        continue;
                    }

                    final Attachment a = mAttachmentsView.generateLocalAttachment(uri);
                    //TS: rong-tang 2016-03-02 EMAIL BUGFIX-1712549 ADD_S
                    if (a == null) {
                        continue;
                    }
                    //TS: rong-tang 2016-03-02 EMAIL BUGFIX-1712549 ADD_E
                    size = mAttachmentsView.addAttachment(mAccount, a, true);//TS: yanhua.chen 2015-6-8 EMAIL CR_996908 MOD

                    Analytics.getInstance().sendEvent("send_intent_attachment",
                            Utils.normalizeMimeType(a.getContentType()), null, size);

                } catch (AttachmentFailureException e) {
                    LogUtils.e(LOG_TAG, e, "Error adding attachment");
                    showAttachmentTooBigToast(e.getErrorRes());
                }
                totalSize += size;
            }
        }
        if (extras.containsKey(Intent.EXTRA_STREAM)) {
            if (!PermissionUtil.checkAndRequestPermissionForResult(this,
                    Manifest.permission.READ_EXTERNAL_STORAGE,
                    PermissionUtil.REQ_CODE_PERMISSION_ADD_ATTACHMENT)) {
                return;
            }
            if (Intent.ACTION_SEND_MULTIPLE.equals(action)) {
                final ArrayList<Uri> uris = extras.getParcelableArrayList(Intent.EXTRA_STREAM);
                ArrayList<Attachment> attachments = new ArrayList<Attachment>();
                for (Uri uri : uris) {
                    if (uri == null) {
                        continue;
                    }
                    try {
                        if (handleSpecialAttachmentUri(uri)) {
                            continue;
                        }

                        final Attachment a = mAttachmentsView.generateLocalAttachment(uri);
                        //TS: rong-tang 2016-03-02 EMAIL BUGFIX-1712549 ADD_S
                        if (a == null) {
                            continue;
                        }
                        //TS: rong-tang 2016-03-02 EMAIL BUGFIX-1712549 ADD_E
                        attachments.add(a);

                        Analytics.getInstance().sendEvent("send_intent_attachment",
                                Utils.normalizeMimeType(a.getContentType()), null, a.size);

                    } catch (AttachmentFailureException e) {
                        LogUtils.e(LOG_TAG, e, "Error adding attachment");
                        String maxSize = AttachmentUtils.convertToHumanReadableSize(getApplicationContext(),
                                mAccount.settings.getMaxAttachmentSize());
                        showErrorToast(getString(R.string.generic_attachment_problem, maxSize));
                    }
                }
                // TS: zhaotianyong 2015-05-08 EMAIL BUGFIX_988459 MOD_S
                totalSize += addAttachments(attachments, false);
                // TS: zhaotianyong 2015-05-08 EMAIL BUGFIX_988459 MOD_E
            } else {
                final Uri uri = extras.getParcelable(Intent.EXTRA_STREAM);
                if (uri != null) {
                    long size = 0;
                    //[BUGFIX]-Modified-BEGIN by TCTNJ.wenlu.wu,12/03/2014,PR-857886
                    if (!handleSpecialAttachmentUri(uri)) {

                        new AsyncTask<Void, Void, Void>() {
                            @Override
                            protected Void doInBackground(Void... params) {
                                try {
                                    Attachment mAttachment = mAttachmentsView.generateLocalAttachment(uri);
                                    android.os.Message msg = new android.os.Message();
                                    msg.what = 1001;
                                    msg.obj = mAttachment;
                                    mHandler.sendMessage(msg);
                                } catch (AttachmentFailureException e) {
                                    LogUtils.e(LOG_TAG, e, "Error adding attachment");
                                    showAttachmentTooBigToast(e.getErrorRes());
                                }
                                return null;
                            }

                            @Override
                            protected void onPostExecute(Void result) {

                            }
                        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                    }
                    //[BUGFIX]-Modified-END by TCTNJ.wenlu.wu,12/03/2014,PR-857886

                    totalSize += size;
                }
            }
        }

        if (totalSize > 0) {
            mAttachmentsChanged = true;
            updateSaveUi();

            Analytics.getInstance().sendEvent("send_intent_with_attachments",
                    Integer.toString(getAttachments().size()), null, totalSize);
        }
    }
}

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

private int getShareAttachmentSize(Intent intent) {
    Bundle extras = intent.getExtras();//from   w  w  w  .j  a v  a2s  .  c  o  m
    if (extras == null) {
        extras = Bundle.EMPTY;
    }
    final String action = intent.getAction();
    int totalSize = 0;
    if (Intent.ACTION_SEND_MULTIPLE.equals(action)) {
        final ArrayList<Uri> uris = extras.getParcelableArrayList(Intent.EXTRA_STREAM);
        ArrayList<Attachment> attachments = new ArrayList<Attachment>();
        for (Uri uri : uris) {
            if (uri == null) {
                continue;
            }
            try {
                if (handleSpecialAttachmentUri(uri)) {
                    continue;
                }

                final Attachment a = mAttachmentsView.generateLocalAttachment(uri);
                //TS: rong-tang 2016-03-02 EMAIL BUGFIX-1712549 ADD_S
                if (a == null) {
                    continue;
                }
                //TS: rong-tang 2016-03-02 EMAIL BUGFIX-1712549 ADD_E
                attachments.add(a);

                Analytics.getInstance().sendEvent("send_intent_attachment",
                        Utils.normalizeMimeType(a.getContentType()), null, a.size);

            } catch (AttachmentFailureException e) {
                LogUtils.e(LOG_TAG, e, "Error adding attachment");
                String maxSize = AttachmentUtils.convertToHumanReadableSize(getApplicationContext(),
                        mAccount.settings.getMaxAttachmentSize());
                showErrorToast(getString(R.string.generic_attachment_problem, maxSize));
            }
        }
        // TS: zhaotianyong 2015-05-08 EMAIL BUGFIX_988459 MOD_S
        totalSize += addAttachments(attachments, false);
        // TS: zhaotianyong 2015-05-08 EMAIL BUGFIX_988459 MOD_E
    } else {
        final Uri uri = extras.getParcelable(Intent.EXTRA_STREAM);
        if (uri != null) {
            long size = 0;
            //[BUGFIX]-Modified-BEGIN by TCTNJ.wenlu.wu,12/03/2014,PR-857886
            if (!handleSpecialAttachmentUri(uri)) {

                new AsyncTask<Void, Void, Void>() {
                    @Override
                    protected Void doInBackground(Void... params) {
                        try {
                            Attachment mAttachment = mAttachmentsView.generateLocalAttachment(uri);
                            android.os.Message msg = new android.os.Message();
                            msg.what = ADD_ATTACHMENT_MSG;
                            msg.obj = mAttachment;
                            mHandler.sendMessage(msg);
                        } catch (AttachmentFailureException e) {
                            LogUtils.e(LOG_TAG, e, "Error adding attachment");
                            // TS: jian.xu 2016-01-11 EMAIL BUGFIX-1307962 MOD_S
                            //Note: show toast must be on ui thread.
                            android.os.Message errorMsg = new android.os.Message();
                            errorMsg.what = ADD_ATTACHMENT_MSG_ERROR;
                            errorMsg.obj = e.getErrorRes();
                            mHandler.sendMessage(errorMsg);
                            //showAttachmentTooBigToast(e.getErrorRes());
                            // TS: jian.xu 2016-01-11 EMAIL BUGFIX-1307962 MOD_E
                        }
                        return null;
                    }

                    @Override
                    protected void onPostExecute(Void result) {

                    }
                }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            }
            //[BUGFIX]-Modified-END by TCTNJ.wenlu.wu,12/03/2014,PR-857886

            totalSize += size;
        }
    }
    return totalSize;
}