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.messic.android.smartphone.activities.main.fragments.queue.PlayQueueFragment.java

private void shareAudio(PlayQueueSongViewHolder holder) {
    File songPath = null;/*from  w  w w .  ja  va 2s  .c o  m*/
    try {
        if (holder.song.isDownloaded(config)) {
            String folderPath = holder.song.calculateExternalStorageFolder();
            String filePath = folderPath + "/" + holder.song.calculateExternalFilename();
            songPath = new File(filePath);
        } else {
            //we create the tmp file at the messic folder
            String tmpFile = UtilFile.getMessicOfflineFolderAbsolutePath() + "/.tmp";
            File outputDir = new File(tmpFile);
            outputDir.mkdirs();
            outputDir = new File(tmpFile + "/share.mp3");
            if (outputDir.exists())
                outputDir.delete();

            String sharePath = holder.song.getURL(config);
            URL url = new URL(sharePath);
            InputStream is = url.openStream();
            FileOutputStream fos = new FileOutputStream(outputDir);
            byte[] b = new byte[1024];
            int length;

            while ((length = is.read(b)) != -1) {
                fos.write(b, 0, length);
            }
            is.close();
            fos.close();
            songPath = outputDir;
        }

        Uri uriOld = Uri.parse(songPath.getAbsolutePath());

        Uri uri2 = MediaStore.Audio.Media.getContentUriForPath(songPath.getAbsolutePath());
        ContentValues values = new ContentValues();
        values.put(MediaStore.MediaColumns.TITLE, holder.song.getName());
        values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");
        values.put(MediaStore.MediaColumns.DATA, songPath.getAbsolutePath());
        values.put(MediaStore.Audio.Media.DATA, songPath.getAbsolutePath());
        values.put(MediaStore.Audio.Media.ARTIST, holder.song.getAlbum().getAuthor().getName());
        values.put(MediaStore.Audio.Media.ALBUM, holder.song.getAlbum().getName());
        values.put(MediaStore.Audio.Media.IS_RINGTONE, false);
        values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);
        values.put(MediaStore.Audio.Media.IS_ALARM, false);
        values.put(MediaStore.Audio.Media.IS_MUSIC, true);
        Uri newUri = getActivity().getContentResolver().insert(uri2, values);

        Intent share = new Intent(Intent.ACTION_SEND_MULTIPLE);
        share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        share.setType("audio/*");

        String shareBody = getString(R.string.share_song_text_start) + " \"" + holder.song.getName() + "\" "
                + getString(R.string.share_song_text_album) + " \"" + holder.song.getAlbum().getName() + "\""
                + getString(R.string.share_song_text_of) + "\"" + holder.song.getAlbum().getAuthor().getName()
                + "\"" + " (I <3 messic)";

        share.putExtra(android.content.Intent.EXTRA_SUBJECT, getString(R.string.share_subject));
        share.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
        //            ArrayList<Uri> uris = new ArrayList<>();
        //            uris.add(uri);
        //share.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
        share.putExtra(Intent.EXTRA_STREAM, uriOld);

        startActivity(Intent.createChooser(share, getString(R.string.share_by)));
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.alfresco.mobile.android.application.managers.ActionUtils.java

public static void actionSendDocumentsToAlfresco(FragmentActivity activity, List<File> files) {
    if (files.size() == 1) {
        actionSendDocumentToAlfresco(activity, files.get(0));
        return;/*w w  w.j  a v  a 2  s. c om*/
    }

    try {
        Intent i = new Intent(activity, PublicDispatcherActivity.class);
        i.setAction(Intent.ACTION_SEND_MULTIPLE);
        ArrayList<Uri> uris = new ArrayList<>();
        // convert from paths to Android friendly Parcelable Uri's
        for (File file : files) {
            Uri u = Uri.fromFile(file);
            uris.add(u);
        }
        i.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
        i.setType(MimeTypeManager.getInstance(activity).getMIMEType("text/plain"));
        activity.startActivity(i);
    } catch (ActivityNotFoundException e) {
        AlfrescoNotificationManager.getInstance(activity).showAlertCrouton(activity,
                R.string.error_unable_share_content);
    }
}

From source file:com.orpheusdroid.screenrecorder.adapter.VideoRecyclerAdapter.java

/**
 * Share the videos selected/*  w  w w  . j  a va2 s  .c  o m*/
 *
 * @param positions Integer ArrayList containing the positions of the videos to be shared
 *
 * @see #shareVideo(int postion)
 */
private void shareVideos(ArrayList<Integer> positions) {
    ArrayList<Uri> videoList = new ArrayList<>();
    for (int position : positions) {
        videoList.add(FileProvider.getUriForFile(context, context.getPackageName() + ".provider",
                videos.get(position).getFile()));
    }
    Intent Shareintent = new Intent().setAction(Intent.ACTION_SEND_MULTIPLE).setType("video/*")
            .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
            .putParcelableArrayListExtra(Intent.EXTRA_STREAM, videoList);
    context.startActivity(
            Intent.createChooser(Shareintent, context.getString(R.string.share_intent_notification_title)));
}

From source file:org.camlistore.CamliActivity.java

@Override
protected void onResume() {
    super.onResume();

    // Check for the right to read the user's files.
    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.READ_EXTERNAL_STORAGE },
                READ_EXTERNAL_STORAGE_PERMISSION_RESPONSE);
    }// www. j a v  a 2 s .  co m

    SharedPreferences sp = getSharedPreferences(Preferences.filename(this.getBaseContext()), 0);
    try {
        HostPort hp = new HostPort(sp.getString(Preferences.HOST, ""));
        if (!hp.isValid()) {
            // Crashes oddly in some Android Instrumentation thing if
            // uncommented:
            // SettingsActivity.show(this);
            // return;
        }
    } catch (NumberFormatException enf) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("Server should be of form [https://]<host[:port]>").setTitle("Invalid Setting");
        AlertDialog alert = builder.create();
        alert.show();
    }

    // Actually start the service before binding to it, so that unbinding from it does not destroy the service.
    Intent intent = getIntent();
    Intent serviceIntent = new Intent(intent);
    serviceIntent.setClass(this, UploadService.class);
    startService(serviceIntent);
    bindService(serviceIntent, mServiceConnection, Context.BIND_AUTO_CREATE);

    // TODO(mpl): maybe remove all of that below. Does the intent action still matter now?
    String action = intent.getAction();
    Log.d(TAG, "onResume; action=" + action);

    if (Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action)) {
        setIntent(new Intent(this, CamliActivity.class));
    } else {
        Log.d(TAG, "Normal CamliActivity viewing.");
    }
}

From source file:org.sufficientlysecure.keychain.ui.EncryptFileActivity.java

/**
 * Handles all actions with this intent/*from ww  w  .j  av a 2s . c o m*/
 *
 * @param intent
 */
private void handleActions(Intent intent) {
    String action = intent.getAction();
    Bundle extras = intent.getExtras();
    String type = intent.getType();
    ArrayList<Uri> uris = new ArrayList<Uri>();

    if (extras == null) {
        extras = new Bundle();
    }

    if (intent.getData() != null) {
        uris.add(intent.getData());
    }

    /*
     * Android's Action
     */

    // When sending to OpenKeychain Encrypt via share menu
    if (Intent.ACTION_SEND.equals(action) && type != null) {
        // Files via content provider, override uri and action
        uris.clear();
        uris.add(intent.<Uri>getParcelableExtra(Intent.EXTRA_STREAM));
    }

    if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) {
        uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
    }

    if (extras.containsKey(EXTRA_ASCII_ARMOR)) {
        mUseArmor = extras.getBoolean(EXTRA_ASCII_ARMOR, true);
    }

    // preselect keys given by intent
    mSigningKeyId = extras.getLong(EXTRA_SIGNATURE_KEY_ID);
    mEncryptionKeyIds = extras.getLongArray(EXTRA_ENCRYPTION_KEY_IDS);

    // Save uris
    mInputUris = uris;

}

From source file:org.alfresco.mobile.android.application.managers.ActionUtils.java

public static void actionSendDocuments(Fragment fr, List<File> files) {
    if (files.size() == 1) {
        actionSendDocument(fr, files.get(0));
        return;/*from   w w w .  j  a  va 2 s . c  o m*/
    }

    try {
        Intent i = new Intent(Intent.ACTION_SEND_MULTIPLE);
        ArrayList<Uri> uris = new ArrayList<>();
        // convert from paths to Android friendly Parcelable Uri's
        for (File file : files) {
            Uri u = Uri.fromFile(file);
            uris.add(u);
        }
        i.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
        i.setType(MimeTypeManager.getInstance(fr.getActivity()).getMIMEType("text/plain"));
        fr.getActivity()
                .startActivity(Intent.createChooser(i, fr.getActivity().getText(R.string.share_content)));
    } catch (ActivityNotFoundException e) {
        AlfrescoNotificationManager.getInstance(fr.getActivity()).showAlertCrouton(fr.getActivity(),
                R.string.error_unable_share_content);
    }
}

From source file:locationkitapp.locationkit.locationkitapp.MapsActivity.java

private void emailVisitHistory() {
    ArrayList<Uri> uris = new ArrayList<Uri>();
    String filename = String.format(Locale.ENGLISH, "data_%d.csv", System.currentTimeMillis());
    File root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
    File file = new File(root, filename);
    if (!file.exists()) {
        try {/*from   w w w .ja  v  a  2  s  .  c  o m*/
            file.createNewFile();
        } catch (IOException e) {
            Log.e(LOG_TAG, "file failed", e);
            return;
        }
    }
    try {
        FileOutputStream os = new FileOutputStream(file);
        os.write(
                "arrival_date,detected_time,visit_id,departure_date,category,subcategory,venue_name,street,city,state,zip,detection_method,latitude,longitude,from_place\n"
                        .getBytes());
        for (Visit v : mVisits) {
            os.write(visitRow(v).getBytes());
        }
        os.close();
    } catch (IOException e) {
        Log.e(LOG_TAG, "ioexception on file", e);
        return;
    }
    uris.add(LKDataManager.EXPORT_DB(this));
    Intent emailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
    emailIntent.setType("text/plain");
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "LocationKitApp ");
    emailIntent.putExtra(Intent.EXTRA_TEXT, "Visits Recorded by LocationKitApp");
    uris.add(Uri.fromFile(file));
    emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
    startActivity(Intent.createChooser(emailIntent, "Pick an Email provider"));
}

From source file:com.openerp.addons.messages.MessageComposeActivty.java

/**
 * Handle message intent filter for attachments
 * //from   w w w . j  av a2 s . co m
 * @param intent
 */
private void handleIntentFilter(Intent intent) {
    attachments_type.put(ATTACHMENT_TYPE.IMAGE, "image/*");
    attachments_type.put(ATTACHMENT_TYPE.TEXT_FILE, "application/*");

    String action = intent.getAction();
    String type = intent.getType();

    // Single attachment
    if (Intent.ACTION_SEND.equals(action) && type != null) {
        Uri fileUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
        file_uris.add(fileUri);
        handleReceivedFile();
    }

    // Multiple Attachments
    if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) {
        ArrayList<Uri> fileUris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
        file_uris.addAll(fileUris);
        handleReceivedFile();

    }

    // note.note send as mail
    if (intent.hasExtra("note_body")) {
        EditText edtBody = (EditText) findViewById(R.id.edtMessageBody);
        String body = intent.getExtras().getString("note_body");
        edtBody.setText(HTMLHelper.stringToHtml(body));
        is_note_body = true;
    }

}

From source file:com.groksolutions.grok.mobile.GrokActivity.java

/**
 * Send user feedback via email with pre-populated email address, screen capture and optional
 * upload identifier//from  w  w  w. ja v  a  2  s  .c o  m
 * <p/>
 *
 * @param uploadId the identifier of the uploaded information; null if none
 */
protected void emailFeedback(final CharSequence uploadId) {
    Intent feedbackIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
    feedbackIntent.putExtra(Intent.EXTRA_EMAIL,
            new String[] { getResources().getText(R.string.feedback_email_address).toString() });
    String subject = getResources().getText(R.string.feedback_email_subject).toString();

    feedbackIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
    feedbackIntent.setType("message/rfc822");
    ArrayList<Uri> uris = new ArrayList<Uri>();
    uris.add(takeScreenCapture(true));
    if (uploadId != null) {
        uris.add(writeTextFileToSend(uploadId.toString()));
    }
    feedbackIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);

    startActivity(Intent.createChooser(feedbackIntent, getResources().getText(R.string.title_feedback)));
}

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

@Override
public void onCreate(final Bundle savedInstanceState) {
    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
    mTwitterWrapper = getTwidereApplication().getTwitterWrapper();
    mResolver = getContentResolver();// w ww.j a v  a 2  s.  c  o m
    super.onCreate(savedInstanceState);
    final long[] account_ids = getAccountIds(this);
    if (account_ids.length <= 0) {
        final Intent intent = new Intent(INTENT_ACTION_TWITTER_LOGIN);
        intent.setClass(this, SignInActivity.class);
        startActivity(intent);
        finish();
        return;
    }
    setContentView(R.layout.compose);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    final Bundle bundle = savedInstanceState != null ? savedInstanceState : getIntent().getExtras();
    final long account_id = bundle != null ? bundle.getLong(INTENT_KEY_ACCOUNT_ID) : -1;
    mAccountIds = bundle != null ? bundle.getLongArray(INTENT_KEY_IDS) : null;
    mInReplyToStatusId = bundle != null ? bundle.getLong(INTENT_KEY_IN_REPLY_TO_ID) : -1;
    mInReplyToScreenName = bundle != null ? bundle.getString(INTENT_KEY_IN_REPLY_TO_SCREEN_NAME) : null;
    mInReplyToName = bundle != null ? bundle.getString(INTENT_KEY_IN_REPLY_TO_NAME) : null;
    mIsImageAttached = bundle != null ? bundle.getBoolean(INTENT_KEY_IS_IMAGE_ATTACHED) : false;
    mIsPhotoAttached = bundle != null ? bundle.getBoolean(INTENT_KEY_IS_PHOTO_ATTACHED) : false;
    mImageUri = bundle != null ? (Uri) bundle.getParcelable(INTENT_KEY_IMAGE_URI) : null;
    final String[] mentions = bundle != null ? bundle.getStringArray(INTENT_KEY_MENTIONS) : null;
    final int notification_id = bundle != null ? bundle.getInt(INTENT_KEY_NOTIFICATION_ID, -1) : -1;
    if (notification_id != -1) {
        mTwitterWrapper.clearNotification(notification_id);
    }
    final String account_screen_name = getAccountScreenName(this, account_id);
    int text_selection_start = -1;
    if (mInReplyToStatusId > 0) {
        if (bundle != null && bundle.getString(INTENT_KEY_TEXT) != null
                && (mentions == null || mentions.length < 1)) {
            mText = bundle.getString(INTENT_KEY_TEXT);
        } else if (mentions != null) {
            final StringBuilder builder = new StringBuilder();
            for (final String mention : mentions) {
                if (mentions.length == 1 && mentions[0].equalsIgnoreCase(account_screen_name)) {
                    builder.append('@' + account_screen_name + ' ');
                } else if (!mention.equalsIgnoreCase(account_screen_name)) {
                    builder.append('@' + mention + ' ');
                }
            }
            mText = builder.toString();
            text_selection_start = mText.indexOf(' ') + 1;
        }

        mIsQuote = bundle != null ? bundle.getBoolean(INTENT_KEY_IS_QUOTE, false) : false;

        final boolean display_screen_name = NAME_DISPLAY_OPTION_SCREEN_NAME
                .equals(mPreferences.getString(PREFERENCE_KEY_NAME_DISPLAY_OPTION, NAME_DISPLAY_OPTION_BOTH));
        if (mInReplyToScreenName != null && mInReplyToName != null) {
            setTitle(getString(mIsQuote ? R.string.quote_user : R.string.reply_to,
                    display_screen_name ? mInReplyToScreenName : mInReplyToName));
        }
        if (mAccountIds == null || mAccountIds.length == 0) {
            mAccountIds = new long[] { account_id };
        }
    } else {
        if (mentions != null) {
            final StringBuilder builder = new StringBuilder();
            for (final String mention : mentions) {
                if (mentions.length == 1 && mentions[0].equalsIgnoreCase(account_screen_name)) {
                    builder.append('@' + account_screen_name + ' ');
                } else if (!mention.equalsIgnoreCase(account_screen_name)) {
                    builder.append('@' + mention + ' ');
                }
            }
            mText = builder.toString();
        }
        if (mAccountIds == null || mAccountIds.length == 0) {
            final long[] ids_in_prefs = ArrayUtils
                    .fromString(mPreferences.getString(PREFERENCE_KEY_COMPOSE_ACCOUNTS, null), ',');
            final long[] intersection = ArrayUtils.intersection(ids_in_prefs, account_ids);
            mAccountIds = intersection.length > 0 ? intersection : account_ids;
        }
        final String action = getIntent().getAction();
        if (Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action)) {
            setTitle(R.string.share);
            final Bundle extras = getIntent().getExtras();
            if (extras != null) {
                if (mText == null) {
                    final CharSequence extra_subject = extras.getCharSequence(Intent.EXTRA_SUBJECT);
                    final CharSequence extra_text = extras.getCharSequence(Intent.EXTRA_TEXT);
                    mText = getShareStatus(this, parseString(extra_subject), parseString(extra_text));
                } else {
                    mText = bundle.getString(INTENT_KEY_TEXT);
                }
                if (mImageUri == null) {
                    final Uri extra_stream = extras.getParcelable(Intent.EXTRA_STREAM);
                    final String content_type = getIntent().getType();
                    if (extra_stream != null && content_type != null && content_type.startsWith("image/")) {
                        final String real_path = getImagePathFromUri(this, extra_stream);
                        final File file = real_path != null ? new File(real_path) : null;
                        if (file != null && file.exists()) {
                            mImageUri = Uri.fromFile(file);
                            mIsImageAttached = true;
                            mIsPhotoAttached = false;
                        } else {
                            mImageUri = null;
                            mIsImageAttached = false;
                        }
                    }
                }
            }
        } else if (bundle != null) {
            if (bundle.getString(INTENT_KEY_TEXT) != null) {
                mText = bundle.getString(INTENT_KEY_TEXT);
            }
        }
    }

    final File image_file = mImageUri != null && "file".equals(mImageUri.getScheme())
            ? new File(mImageUri.getPath())
            : null;
    final boolean image_file_valid = image_file != null && image_file.exists();
    mImageThumbnailPreview.setVisibility(image_file_valid ? View.VISIBLE : View.GONE);
    if (image_file_valid) {
        reloadAttachedImageThumbnail(image_file);
    }

    mImageThumbnailPreview.setOnClickListener(this);
    mImageThumbnailPreview.setOnLongClickListener(this);
    mMenuBar.setOnMenuItemClickListener(this);
    mMenuBar.inflate(R.menu.menu_compose);
    final Menu menu = mMenuBar.getMenu();
    final MenuItem extensions = menu.findItem(MENU_EXTENSIONS_SUBMENU);
    if (extensions != null) {
        final Intent intent = new Intent(INTENT_ACTION_EXTENSION_COMPOSE);
        final Bundle extras = new Bundle();
        final String screen_name = mAccountIds != null && mAccountIds.length > 0
                ? getAccountScreenName(this, mAccountIds[0])
                : null;
        extras.putString(INTENT_KEY_TEXT, parseString(mEditText.getText()));
        extras.putString(INTENT_KEY_IN_REPLY_TO_SCREEN_NAME, mInReplyToScreenName);
        extras.putString(INTENT_KEY_IN_REPLY_TO_NAME, mInReplyToName);
        extras.putString(INTENT_KEY_SCREEN_NAME, screen_name);
        extras.putLong(INTENT_KEY_IN_REPLY_TO_ID, mInReplyToStatusId);
        intent.putExtras(extras);
        addIntentToSubMenu(this, extensions.getSubMenu(), intent);
    }
    mMenuBar.show();
    if (mPreferences.getBoolean(PREFERENCE_KEY_QUICK_SEND, false)) {
        mEditText.setOnEditorActionListener(this);
    }
    mEditText.addTextChangedListener(this);
    if (mText != null) {
        mEditText.setText(mText);
        if (mIsQuote) {
            mEditText.setSelection(0);
        } else if (text_selection_start != -1 && text_selection_start < mEditText.length()
                && mEditText.length() > 0) {
            mEditText.setSelection(text_selection_start, mEditText.length() - 1);
        } else if (mEditText.length() > 0) {
            mEditText.setSelection(mEditText.length());
        }
    }
    setMenu();
    mColorIndicator.setColors(getAccountColors(this, mAccountIds));
    mContentModified = savedInstanceState != null ? savedInstanceState.getBoolean(INTENT_KEY_CONTENT_MODIFIED)
            : false;
    mIsPossiblySensitive = savedInstanceState != null
            ? savedInstanceState.getBoolean(INTENT_KEY_IS_POSSIBLY_SENSITIVE)
            : false;
}