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:org.gnucash.android.export.ExportAsyncTask.java

/**
 * Starts an intent chooser to allow the user to select an activity to receive
 * the exported files./* www  .  java  2s . c o m*/
 * @param paths list of full paths of the files to send to the activity.
 */
private void shareFiles(List<String> paths) {
    Intent shareIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
    shareIntent.setType("text/xml");

    ArrayList<Uri> exportFiles = convertFilePathsToUris(paths);
    shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, exportFiles);
    shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

    shareIntent.putExtra(Intent.EXTRA_SUBJECT,
            mContext.getString(R.string.title_export_email, mExportParams.getExportFormat().name()));

    String defaultEmail = PreferenceManager.getDefaultSharedPreferences(mContext)
            .getString(mContext.getString(R.string.key_default_export_email), null);
    if (defaultEmail != null && defaultEmail.trim().length() > 0)
        shareIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { defaultEmail });

    SimpleDateFormat formatter = (SimpleDateFormat) SimpleDateFormat.getDateTimeInstance();
    ArrayList<CharSequence> extraText = new ArrayList<>();
    extraText.add(mContext.getString(R.string.description_export_email) + " "
            + formatter.format(new Date(System.currentTimeMillis())));
    shareIntent.putExtra(Intent.EXTRA_TEXT, extraText);

    if (mContext instanceof Activity) {
        List<ResolveInfo> activities = mContext.getPackageManager().queryIntentActivities(shareIntent, 0);
        if (activities != null && !activities.isEmpty()) {
            mContext.startActivity(Intent.createChooser(shareIntent,
                    mContext.getString(R.string.title_select_export_destination)));
        } else {
            Toast.makeText(mContext, R.string.toast_no_compatible_apps_to_receive_export, Toast.LENGTH_LONG)
                    .show();
        }
    }
}

From source file:com.fa.mastodon.activity.ComposeActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_compose);
    ButterKnife.bind(this);

    // Setup the toolbar.
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//from  ww  w .  j  a  v  a  2 s. c  o m
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setTitle(null);
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowHomeEnabled(true);
        Drawable closeIcon = AppCompatResources.getDrawable(this, R.drawable.ic_close_24dp);
        ThemeUtils.setDrawableTint(this, closeIcon, R.attr.compose_close_button_tint);
        actionBar.setHomeAsUpIndicator(closeIcon);
    }

    // Setup the interface buttons.
    floatingBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onSendClicked();
        }
    });
    pickBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onMediaPick();
        }
    });
    takeBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            initiateCameraApp();
        }
    });
    nsfwBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            toggleNsfw();
        }
    });
    visibilityBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showComposeOptions();
        }
    });

    /* Initialise all the state, or restore it from a previous run, to determine a "starting"
     * state. */
    SharedPreferences preferences = getPrivatePreferences();

    String startingVisibility;
    boolean startingHideText;
    String startingContentWarning = null;
    ArrayList<SavedQueuedMedia> savedMediaQueued = null;
    if (savedInstanceState != null) {
        showMarkSensitive = savedInstanceState.getBoolean("showMarkSensitive");
        startingVisibility = savedInstanceState.getString("statusVisibility");
        statusMarkSensitive = savedInstanceState.getBoolean("statusMarkSensitive");
        startingHideText = savedInstanceState.getBoolean("statusHideText");
        // Keep these until everything needed to put them in the queue is finished initializing.
        savedMediaQueued = savedInstanceState.getParcelableArrayList("savedMediaQueued");
        // These are for restoring an in-progress commit content operation.
        InputContentInfoCompat previousInputContentInfo = InputContentInfoCompat
                .wrap(savedInstanceState.getParcelable("commitContentInputContentInfo"));
        int previousFlags = savedInstanceState.getInt("commitContentFlags");
        if (previousInputContentInfo != null) {
            onCommitContentInternal(previousInputContentInfo, previousFlags);
        }
    } else {
        showMarkSensitive = false;
        startingVisibility = preferences.getString("rememberedVisibility", "public");
        statusMarkSensitive = false;
        startingHideText = false;
    }

    /* If the composer is started up as a reply to another post, override the "starting" state
     * based on what the intent from the reply request passes. */
    Intent intent = getIntent();

    String[] mentionedUsernames = null;
    inReplyToId = null;
    if (intent != null) {
        inReplyToId = intent.getStringExtra("in_reply_to_id");
        String replyVisibility = intent.getStringExtra("reply_visibility");

        if (replyVisibility != null && startingVisibility != null) {
            // Lowest possible visibility setting in response
            if (startingVisibility.equals("private") || replyVisibility.equals("private")) {
                startingVisibility = "private";
            } else if (startingVisibility.equals("unlisted") || replyVisibility.equals("unlisted")) {
                startingVisibility = "unlisted";
            } else {
                startingVisibility = replyVisibility;
            }
        }

        mentionedUsernames = intent.getStringArrayExtra("mentioned_usernames");

        if (inReplyToId != null) {
            startingHideText = !intent.getStringExtra("content_warning").equals("");
            if (startingHideText) {
                startingContentWarning = intent.getStringExtra("content_warning");
            }
        }
    }

    /* If the currently logged in account is locked, its posts should default to private. This
     * should override even the reply settings, so this must be done after those are set up. */
    if (preferences.getBoolean("loggedInAccountLocked", false)) {
        startingVisibility = "private";
    }

    // After the starting state is finalised, the interface can be set to reflect this state.
    setStatusVisibility(startingVisibility);
    postProgress.setVisibility(View.INVISIBLE);
    updateNsfwButtonColor();

    // Setup the main text field.
    setEditTextMimeTypes(null); // new String[] { "image/gif", "image/webp" }
    final int mentionColour = ThemeUtils.getColor(this, R.attr.compose_mention_color);
    SpanUtils.highlightSpans(textEditor.getText(), mentionColour);
    textEditor.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            updateVisibleCharactersLeft();
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            SpanUtils.highlightSpans(editable, mentionColour);
        }
    });

    // Add any mentions to the text field when a reply is first composed.
    if (mentionedUsernames != null) {
        StringBuilder builder = new StringBuilder();
        for (String name : mentionedUsernames) {
            builder.append('@');
            builder.append(name);
            builder.append(' ');
        }
        textEditor.setText(builder);
        textEditor.setSelection(textEditor.length());
    }

    // Initialise the content warning editor.
    contentWarningEditor.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            updateVisibleCharactersLeft();
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    showContentWarning(startingHideText);
    if (startingContentWarning != null) {
        contentWarningEditor.setText(startingContentWarning);
    }

    // Initialise the empty media queue state.
    mediaQueued = new ArrayList<>();
    waitForMediaLatch = new CountUpDownLatch();
    statusAlreadyInFlight = false;

    // These can only be added after everything affected by the media queue is initialized.
    if (savedMediaQueued != null) {
        for (SavedQueuedMedia item : savedMediaQueued) {
            addMediaToQueue(item.type, item.preview, item.uri, item.mediaSize);
        }
    } else if (intent != null && savedInstanceState == null) {
        /* Get incoming images being sent through a share action from another app. Only do this
         * when savedInstanceState is null, otherwise both the images from the intent and the
         * instance state will be re-queued. */
        String type = intent.getType();
        if (type != null) {
            if (type.startsWith("image/")) {
                List<Uri> uriList = new ArrayList<>();
                switch (intent.getAction()) {
                case Intent.ACTION_SEND: {
                    Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
                    if (uri != null) {
                        uriList.add(uri);
                    }
                    break;
                }
                case Intent.ACTION_SEND_MULTIPLE: {
                    ArrayList<Uri> list = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
                    if (list != null) {
                        for (Uri uri : list) {
                            if (uri != null) {
                                uriList.add(uri);
                            }
                        }
                    }
                    break;
                }
                }
                for (Uri uri : uriList) {
                    long mediaSize = getMediaSize(getContentResolver(), uri);
                    pickMedia(uri, mediaSize);
                }
            } else if (type.equals("text/plain")) {
                String action = intent.getAction();
                if (action != null && action.equals(Intent.ACTION_SEND)) {
                    String text = intent.getStringExtra(Intent.EXTRA_TEXT);
                    if (text != null) {
                        int start = Math.max(textEditor.getSelectionStart(), 0);
                        int end = Math.max(textEditor.getSelectionEnd(), 0);
                        int left = Math.min(start, end);
                        int right = Math.max(start, end);
                        textEditor.getText().replace(left, right, text, 0, text.length());
                    }
                }
            }
        }
    }
}

From source file:net.maa123.tatuky.ComposeActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_compose);
    ButterKnife.bind(this);

    // Setup the toolbar.
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//from w  w  w.jav  a  2 s. c  o  m
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setTitle(null);
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowHomeEnabled(true);
        Drawable closeIcon = AppCompatResources.getDrawable(this, R.drawable.ic_close_24dp);
        ThemeUtils.setDrawableTint(this, closeIcon, R.attr.compose_close_button_tint);
        actionBar.setHomeAsUpIndicator(closeIcon);
    }

    // Setup the interface buttons.
    floatingBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onSendClicked();
        }
    });
    pickBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onMediaPick();
        }
    });
    takeBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            initiateCameraApp();
        }
    });
    nsfwBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            toggleNsfw();
        }
    });
    visibilityBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showComposeOptions();
        }
    });

    /* Initialise all the state, or restore it from a previous run, to determine a "starting"
     * state. */
    SharedPreferences preferences = getPrivatePreferences();

    String startingVisibility;
    boolean startingHideText;
    String startingContentWarning = null;
    ArrayList<SavedQueuedMedia> savedMediaQueued = null;
    if (savedInstanceState != null) {
        showMarkSensitive = savedInstanceState.getBoolean("showMarkSensitive");
        startingVisibility = savedInstanceState.getString("statusVisibility");
        statusMarkSensitive = savedInstanceState.getBoolean("statusMarkSensitive");
        startingHideText = savedInstanceState.getBoolean("statusHideText");
        // Keep these until everything needed to put them in the queue is finished initializing.
        savedMediaQueued = savedInstanceState.getParcelableArrayList("savedMediaQueued");
        // These are for restoring an in-progress commit content operation.
        InputContentInfoCompat previousInputContentInfo = InputContentInfoCompat
                .wrap(savedInstanceState.getParcelable("commitContentInputContentInfo"));
        int previousFlags = savedInstanceState.getInt("commitContentFlags");
        if (previousInputContentInfo != null) {
            onCommitContentInternal(previousInputContentInfo, previousFlags);
        }
    } else {
        showMarkSensitive = false;
        startingVisibility = preferences.getString("rememberedVisibility", "public");
        statusMarkSensitive = false;
        startingHideText = false;
    }

    /* If the composer is started up as a reply to another post, override the "starting" state
     * based on what the intent from the reply request passes. */
    Intent intent = getIntent();

    String[] mentionedUsernames = null;
    inReplyToId = null;
    if (intent != null) {
        inReplyToId = intent.getStringExtra("in_reply_to_id");
        String replyVisibility = intent.getStringExtra("reply_visibility");

        if (replyVisibility != null && startingVisibility != null) {
            // Lowest possible visibility setting in response
            if (startingVisibility.equals("direct") || replyVisibility.equals("direct")) {
                startingVisibility = "direct";
            } else if (startingVisibility.equals("private") || replyVisibility.equals("private")) {
                startingVisibility = "private";
            } else if (startingVisibility.equals("unlisted") || replyVisibility.equals("unlisted")) {
                startingVisibility = "unlisted";
            } else {
                startingVisibility = replyVisibility;
            }
        }

        mentionedUsernames = intent.getStringArrayExtra("mentioned_usernames");

        if (inReplyToId != null) {
            startingHideText = !intent.getStringExtra("content_warning").equals("");
            if (startingHideText) {
                startingContentWarning = intent.getStringExtra("content_warning");
            }
        }
    }

    /* If the currently logged in account is locked, its posts should default to private. This
     * should override even the reply settings, so this must be done after those are set up. */
    if (preferences.getBoolean("loggedInAccountLocked", false)) {
        startingVisibility = "private";
    }

    // After the starting state is finalised, the interface can be set to reflect this state.
    setStatusVisibility(startingVisibility);
    postProgress.setVisibility(View.INVISIBLE);
    updateNsfwButtonColor();

    // Setup the main text field.
    setEditTextMimeTypes(null); // new String[] { "image/gif", "image/webp" }
    final int mentionColour = ThemeUtils.getColor(this, R.attr.compose_mention_color);
    SpanUtils.highlightSpans(textEditor.getText(), mentionColour);
    textEditor.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            updateVisibleCharactersLeft();
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            SpanUtils.highlightSpans(editable, mentionColour);
        }
    });

    // Add any mentions to the text field when a reply is first composed.
    if (mentionedUsernames != null) {
        StringBuilder builder = new StringBuilder();
        for (String name : mentionedUsernames) {
            builder.append('@');
            builder.append(name);
            builder.append(' ');
        }
        textEditor.setText(builder);
        textEditor.setSelection(textEditor.length());
    }

    // Initialise the content warning editor.
    contentWarningEditor.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            updateVisibleCharactersLeft();
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    showContentWarning(startingHideText);
    if (startingContentWarning != null) {
        contentWarningEditor.setText(startingContentWarning);
    }

    // Initialise the empty media queue state.
    mediaQueued = new ArrayList<>();
    waitForMediaLatch = new CountUpDownLatch();
    statusAlreadyInFlight = false;

    // These can only be added after everything affected by the media queue is initialized.
    if (savedMediaQueued != null) {
        for (SavedQueuedMedia item : savedMediaQueued) {
            addMediaToQueue(item.type, item.preview, item.uri, item.mediaSize);
        }
    } else if (intent != null && savedInstanceState == null) {
        /* Get incoming images being sent through a share action from another app. Only do this
         * when savedInstanceState is null, otherwise both the images from the intent and the
         * instance state will be re-queued. */
        String type = intent.getType();
        if (type != null) {
            if (type.startsWith("image/")) {
                List<Uri> uriList = new ArrayList<>();
                switch (intent.getAction()) {
                case Intent.ACTION_SEND: {
                    Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
                    if (uri != null) {
                        uriList.add(uri);
                    }
                    break;
                }
                case Intent.ACTION_SEND_MULTIPLE: {
                    ArrayList<Uri> list = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
                    if (list != null) {
                        for (Uri uri : list) {
                            if (uri != null) {
                                uriList.add(uri);
                            }
                        }
                    }
                    break;
                }
                }
                for (Uri uri : uriList) {
                    long mediaSize = getMediaSize(getContentResolver(), uri);
                    pickMedia(uri, mediaSize);
                }
            } else if (type.equals("text/plain")) {
                String action = intent.getAction();
                if (action != null && action.equals(Intent.ACTION_SEND)) {
                    String text = intent.getStringExtra(Intent.EXTRA_TEXT);
                    if (text != null) {
                        int start = Math.max(textEditor.getSelectionStart(), 0);
                        int end = Math.max(textEditor.getSelectionEnd(), 0);
                        int left = Math.min(start, end);
                        int right = Math.max(start, end);
                        textEditor.getText().replace(left, right, text, 0, text.length());
                    }
                }
            }
        }
    }
}

From source file:link.kjr.file_manager.MainActivity.java

public void sendSingleFile(String path) {

    Intent i = new Intent();
    ArrayList<Uri> files = new ArrayList<>();
    files.add(Uri.fromFile(new File(path)));
    i.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files);
    i.setType("*/*");
    i.setAction(Intent.ACTION_SEND_MULTIPLE);
    startActivity(Intent.createChooser(i, getString(R.string.send_file)));

}

From source file:it.feio.android.omninotes.DetailFragment.java

private void handleIntents() {
    Intent i = mainActivity.getIntent();

    if (IntentChecker.checkAction(i, Constants.ACTION_MERGE)) {
        noteOriginal = new Note();
        note = new Note(noteOriginal);
        noteTmp = getArguments().getParcelable(Constants.INTENT_NOTE);
        if (i.getStringArrayListExtra("merged_notes") != null) {
            mergedNotesIds = i.getStringArrayListExtra("merged_notes");
        }//from   w  ww . j  a  v  a 2s  .  c o m
    }

    // Action called from home shortcut
    if (IntentChecker.checkAction(i, Constants.ACTION_SHORTCUT, Constants.ACTION_NOTIFICATION_CLICK)) {
        afterSavedReturnsToList = false;
        noteOriginal = DbHelper.getInstance().getNote(i.getLongExtra(Constants.INTENT_KEY, 0));
        // Checks if the note pointed from the shortcut has been deleted
        try {
            note = new Note(noteOriginal);
            noteTmp = new Note(noteOriginal);
        } catch (NullPointerException e) {
            mainActivity.showToast(getText(R.string.shortcut_note_deleted), Toast.LENGTH_LONG);
            mainActivity.finish();
        }
    }

    // Check if is launched from a widget
    if (IntentChecker.checkAction(i, Constants.ACTION_WIDGET, Constants.ACTION_TAKE_PHOTO)) {

        afterSavedReturnsToList = false;
        showKeyboard = true;

        //  with tags to set tag
        if (i.hasExtra(Constants.INTENT_WIDGET)) {
            String widgetId = i.getExtras().get(Constants.INTENT_WIDGET).toString();
            if (widgetId != null) {
                String sqlCondition = prefs.getString(Constants.PREF_WIDGET_PREFIX + widgetId, "");
                String categoryId = TextHelper.checkIntentCategory(sqlCondition);
                if (categoryId != null) {
                    Category category;
                    try {
                        category = DbHelper.getInstance().getCategory(Long.parseLong(categoryId));
                        noteTmp = new Note();
                        noteTmp.setCategory(category);
                    } catch (NumberFormatException e) {
                        Log.e(Constants.TAG, "Category with not-numeric value!", e);
                    }
                }
            }
        }

        // Sub-action is to take a photo
        if (IntentChecker.checkAction(i, Constants.ACTION_TAKE_PHOTO)) {
            takePhoto();
        }
    }

    /**
     * Handles third party apps requests of sharing
     */
    if (IntentChecker.checkAction(i, Intent.ACTION_SEND, Intent.ACTION_SEND_MULTIPLE,
            Constants.INTENT_GOOGLE_NOW) && i.getType() != null) {

        afterSavedReturnsToList = false;

        if (noteTmp == null)
            noteTmp = new Note();

        // Text title
        String title = i.getStringExtra(Intent.EXTRA_SUBJECT);
        if (title != null) {
            noteTmp.setTitle(title);
        }

        // Text content
        String content = i.getStringExtra(Intent.EXTRA_TEXT);
        if (content != null) {
            noteTmp.setContent(content);
        }

        // Single attachment data
        Uri uri = i.getParcelableExtra(Intent.EXTRA_STREAM);
        // Due to the fact that Google Now passes intent as text but with
        // audio recording attached the case must be handled in specific way
        if (uri != null && !Constants.INTENT_GOOGLE_NOW.equals(i.getAction())) {
            String name = FileHelper.getNameFromUri(mainActivity, uri);
            AttachmentTask task = new AttachmentTask(this, uri, name, this);
            task.execute();
        }

        // Multiple attachment data
        ArrayList<Uri> uris = i.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
        if (uris != null) {
            for (Uri uriSingle : uris) {
                String name = FileHelper.getNameFromUri(mainActivity, uriSingle);
                AttachmentTask task = new AttachmentTask(this, uriSingle, name, this);
                task.execute();
            }
        }

        //         i.setAction(null);
    }

    if (IntentChecker.checkAction(i, Intent.ACTION_MAIN, Constants.ACTION_WIDGET_SHOW_LIST)) {
        showKeyboard = true;
    }

}

From source file:link.kjr.file_manager.MainActivity.java

public void send(MenuItem item) {
    ArrayList<Uri> files = new ArrayList<>();
    for (String file : selectedFiles) {

        files.add(Uri.fromFile(new File(file)));
    }/*from  w  w w  .  j  a v  a2 s  .c om*/
    Intent share = new Intent();
    share.setAction(Intent.ACTION_SEND_MULTIPLE);
    share.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files);
    share.setType("*/*");
    startActivity(Intent.createChooser(share, getString(R.string.send_files)));
}

From source file:org.brandroid.openmanager.util.EventHandler.java

public void sendFile(final Collection<OpenPath> path, final Context mContext) {
    String name;//from  w  w w  . j  a  v  a  2 s .  c o m
    CharSequence[] list = { "Bluetooth", "Email" };
    final OpenPath[] files = new OpenPath[path.size()];
    path.toArray(files);
    final int num = path.size();

    if (num == 1)
        name = files[0].getName();
    else
        name = path.size() + " " + getResourceString(mContext, R.string.s_files) + ".";

    AlertDialog.Builder b = new AlertDialog.Builder(mContext);
    b.setTitle(getResourceString(mContext, R.string.s_title_send).toString().replace("xxx", name))
            .setIcon(R.drawable.bluetooth).setItems(list, new OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {
                    switch (which) {
                    case 0:
                        Intent bt = new Intent(mContext, BluetoothActivity.class);

                        bt.putExtra("paths", files);
                        mContext.startActivity(bt);
                        break;

                    case 1:
                        ArrayList<Uri> uris = new ArrayList<Uri>();
                        Intent mail = new Intent();
                        mail.setType("application/mail");

                        if (num == 1) {
                            mail.setAction(android.content.Intent.ACTION_SEND);
                            mail.putExtra(Intent.EXTRA_STREAM, files[0].getUri());
                            mContext.startActivity(mail);
                            break;
                        }

                        for (int i = 0; i < num; i++)
                            uris.add(files[i].getUri());

                        mail.setAction(android.content.Intent.ACTION_SEND_MULTIPLE);
                        mail.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
                        mContext.startActivity(mail);
                        break;
                    }
                }
            }).create().show();
}

From source file:com.dycody.android.idealnote.DetailFragment.java

private void handleIntents() {
    Intent i = mainActivity.getIntent();

    if (IntentChecker.checkAction(i, Constants.ACTION_MERGE)) {
        noteOriginal = new Note();
        note = new Note(noteOriginal);
        noteTmp = getArguments().getParcelable(Constants.INTENT_NOTE);
        if (i.getStringArrayListExtra("merged_notes") != null) {
            mergedNotesIds = i.getStringArrayListExtra("merged_notes");
        }//ww w . j  a  va2  s.c om
    }

    // Action called from home shortcut
    if (IntentChecker.checkAction(i, Constants.ACTION_SHORTCUT, Constants.ACTION_NOTIFICATION_CLICK)) {
        afterSavedReturnsToList = false;
        noteOriginal = DbHelper.getInstance().getNote(i.getLongExtra(Constants.INTENT_KEY, 0));
        // Checks if the note pointed from the shortcut has been deleted
        try {
            note = new Note(noteOriginal);
            noteTmp = new Note(noteOriginal);
        } catch (NullPointerException e) {
            mainActivity.showToast(getText(R.string.shortcut_note_deleted), Toast.LENGTH_LONG);
            mainActivity.finish();
        }
    }

    // Check if is launched from a widget
    if (IntentChecker.checkAction(i, Constants.ACTION_WIDGET, Constants.ACTION_TAKE_PHOTO)) {

        afterSavedReturnsToList = false;
        showKeyboard = true;

        //  with tags to set tag
        if (i.hasExtra(Constants.INTENT_WIDGET)) {
            String widgetId = i.getExtras().get(Constants.INTENT_WIDGET).toString();
            if (widgetId != null) {
                String sqlCondition = prefs.getString(Constants.PREF_WIDGET_PREFIX + widgetId, "");
                String categoryId = TextHelper.checkIntentCategory(sqlCondition);
                if (categoryId != null) {
                    Category category;
                    try {
                        category = DbHelper.getInstance().getCategory(Long.parseLong(categoryId));
                        noteTmp = new Note();
                        noteTmp.setCategory(category);
                    } catch (NumberFormatException e) {
                        Log.e(Constants.TAG, "Category with not-numeric value!", e);
                    }
                }
            }
        }

        // Sub-action is to take a photo
        if (IntentChecker.checkAction(i, Constants.ACTION_TAKE_PHOTO)) {
            takePhoto();
        }
    }

    /**
     * Handles third party apps requests of sharing
     */
    if (IntentChecker.checkAction(i, Intent.ACTION_SEND, Intent.ACTION_SEND_MULTIPLE,
            Constants.INTENT_GOOGLE_NOW) && i.getType() != null) {

        afterSavedReturnsToList = false;

        if (noteTmp == null)
            noteTmp = new Note();

        // Text title
        String title = i.getStringExtra(Intent.EXTRA_SUBJECT);
        if (title != null) {
            noteTmp.setTitle(title);
        }

        // Text content
        String content = i.getStringExtra(Intent.EXTRA_TEXT);
        if (content != null) {
            noteTmp.setContent(content);
        }

        // Single attachment data
        Uri uri = i.getParcelableExtra(Intent.EXTRA_STREAM);
        // Due to the fact that Google Now passes intent as text but with
        // audio recording attached the case must be handled in specific way
        if (uri != null && !Constants.INTENT_GOOGLE_NOW.equals(i.getAction())) {
            String name = FileHelper.getNameFromUri(mainActivity, uri);
            new AttachmentTask(this, uri, name, this).execute();
        }

        // Multiple attachment data
        ArrayList<Uri> uris = i.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
        if (uris != null) {
            for (Uri uriSingle : uris) {
                String name = FileHelper.getNameFromUri(mainActivity, uriSingle);
                new AttachmentTask(this, uriSingle, name, this).execute();
            }
        }
    }

    if (IntentChecker.checkAction(i, Intent.ACTION_MAIN, Constants.ACTION_WIDGET_SHOW_LIST,
            Constants.ACTION_SHORTCUT_WIDGET, Constants.ACTION_WIDGET)) {
        showKeyboard = true;
    }

    i.setAction(null);
}

From source file:com.synox.android.ui.activity.Uploader.java

private void prepareStreamsToUpload() {
    try {/* w w  w.  j  a v a 2 s  .  c o m*/
        if (getIntent().getAction().equals(Intent.ACTION_SEND)) {
            mStreamsToUpload = new ArrayList<>();
            mStreamsToUpload.add(getIntent().getParcelableExtra(Intent.EXTRA_STREAM));
        } else if (getIntent().getAction().equals(Intent.ACTION_SEND_MULTIPLE)) {
            mStreamsToUpload = getIntent().getParcelableArrayListExtra(Intent.EXTRA_STREAM);
        }
    } catch (NullPointerException npe) {
        Log_OC.e(this.getClass().getName(), "Unknown error occurred. Message: " + npe.getLocalizedMessage());
    }
}

From source file:com.cerema.cloud2.ui.activity.Uploader.java

private void prepareStreamsToUpload() {
    if (getIntent().getAction().equals(Intent.ACTION_SEND)) {
        mStreamsToUpload = new ArrayList<Parcelable>();
        mStreamsToUpload.add(getIntent().getParcelableExtra(Intent.EXTRA_STREAM));
    } else if (getIntent().getAction().equals(Intent.ACTION_SEND_MULTIPLE)) {
        mStreamsToUpload = getIntent().getParcelableArrayListExtra(Intent.EXTRA_STREAM);
    }//from w ww . j  a v  a2  s  .  c o  m
}