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:pl.mrwojtek.sensrec.app.Records.java

public boolean shareActivated() {
    ArrayList<Uri> files = new ArrayList<>();
    for (RecordEntry recordEntry : records) {
        if (recordEntry.isActivated()) {
            files.add(Uri.fromFile(recordEntry.getFile()));
        }//from   ww  w  . j  av  a 2s  .  c om
    }

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND_MULTIPLE);
    intent.setType("application/octet-stream");
    intent.putExtra(Intent.EXTRA_SUBJECT, "Sensors Record recordings.");
    intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files);

    if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
        getActivity().startActivity(intent);
        return true;
    } else {
        return false;
    }
}

From source file:org.alfresco.mobile.android.application.fragments.upload.UploadFormFragment.java

@Override
public void onStart() {
    super.onStart();

    Intent intent = getActivity().getIntent();
    String action = intent.getAction();
    String type = intent.getType();
    if (files != null) {
        files.clear();//from w w  w . j  a va  2  s.c o m
    }

    try {
        if (Intent.ACTION_SEND_MULTIPLE.equals(action)) {
            if (AndroidVersion.isJBOrAbove()) {
                ClipData clipdata = intent.getClipData();
                if (clipdata != null && clipdata.getItemCount() > 1) {
                    Item item = null;
                    for (int i = 0; i < clipdata.getItemCount(); i++) {
                        item = clipdata.getItemAt(i);
                        Uri uri = item.getUri();
                        if (uri != null) {
                            retrieveIntentInfo(uri);
                        } else {
                            String timeStamp = new SimpleDateFormat("yyyyddMM_HHmmss").format(new Date());
                            File localParentFolder = StorageManager.getCacheDir(getActivity(),
                                    "AlfrescoMobile/import");
                            File f = createFile(localParentFolder, timeStamp + ".txt",
                                    item.getText().toString());
                            if (f.exists()) {
                                retrieveIntentInfo(Uri.fromFile(f));
                            }
                        }
                        if (!files.contains(file)) {
                            files.add(file);
                        }
                    }
                }
            } else {
                if (intent.getExtras() != null
                        && intent.getExtras().get(Intent.EXTRA_STREAM) instanceof ArrayList) {
                    @SuppressWarnings("unchecked")
                    List<Object> attachments = (ArrayList<Object>) intent.getExtras().get(Intent.EXTRA_STREAM);
                    for (Object object : attachments) {
                        if (object instanceof Uri) {
                            Uri uri = (Uri) object;
                            if (uri != null) {
                                retrieveIntentInfo(uri);
                            }
                            if (!files.contains(file)) {
                                files.add(file);
                            }
                        }
                    }
                } else if (file == null || fileName == null) {
                    MessengerManager.showLongToast(getActivity(),
                            getString(R.string.import_unsupported_intent));
                    getActivity().finish();
                    return;
                }
            }
        } else {
            // Manage only one clip data. If multiple we ignore.
            if (AndroidVersion.isJBOrAbove() && (!Intent.ACTION_SEND.equals(action) || type == null)) {
                ClipData clipdata = intent.getClipData();
                if (clipdata != null && clipdata.getItemCount() == 1 && clipdata.getItemAt(0) != null
                        && (clipdata.getItemAt(0).getText() != null
                                || clipdata.getItemAt(0).getUri() != null)) {
                    Item item = clipdata.getItemAt(0);
                    Uri uri = item.getUri();
                    if (uri != null) {
                        retrieveIntentInfo(uri);
                    } else {
                        String timeStamp = new SimpleDateFormat("yyyyddMM_HHmmss").format(new Date());
                        File localParentFolder = StorageManager.getCacheDir(getActivity(),
                                "AlfrescoMobile/import");
                        File f = createFile(localParentFolder, timeStamp + ".txt", item.getText().toString());
                        if (f.exists()) {
                            retrieveIntentInfo(Uri.fromFile(f));
                        }
                    }
                }
            }

            if (file == null && Intent.ACTION_SEND.equals(action) && type != null) {
                Uri uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
                retrieveIntentInfo(uri);
            } else if (action == null && intent.getData() != null) {
                retrieveIntentInfo(intent.getData());
            } else if (file == null || fileName == null) {
                MessengerManager.showLongToast(getActivity(), getString(R.string.import_unsupported_intent));
                getActivity().finish();
                return;
            }
            if (!files.contains(file)) {
                files.add(file);
            }
        }
    } catch (AlfrescoAppException e) {
        org.alfresco.mobile.android.application.manager.ActionManager.actionDisplayError(this, e);
        getActivity().finish();
        return;
    }

    if (adapter == null && files != null) {
        adapter = new FileExplorerAdapter(this, R.layout.app_list_progress_row, files);
        if (lv != null) {
            lv.setAdapter(adapter);
        } else if (spinnerDoc != null) {
            spinnerDoc.setAdapter(adapter);
        }
    }

    Button b = UIUtils.initCancel(rootView, R.string.cancel);
    b.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            getActivity().finish();
        }
    });

    b = UIUtils.initValidation(rootView, R.string.next);
    b.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            next();
        }
    });

    refreshImportFolder();
}

From source file:it.uniroma3.android.gpstracklogger.adapters.AdapterTrack.java

private void sendMail(int position) {
    Track track = Session.getController().getImportedTracks().get(position);
    final Intent intent = new Intent(Intent.ACTION_SEND);

    intent.setType("*/*");
    intent.setAction(Intent.ACTION_SEND_MULTIPLE);
    intent.putExtra(Intent.EXTRA_SUBJECT, "Traccia: " + track.getName());

    ArrayList<Uri> chosenFile = new ArrayList<>();
    String path = track.getPath();
    File file = new File(path);
    Uri uri = null;//from   w w  w.j  a  v  a2 s. c  o m
    if (path.contains(AppSettings.getDirectory()))
        uri = FileProvider.getUriForFile(activity, "it.uniroma3.android.gpstracklogger.GPSMainActivity", file);
    else
        uri = Uri.fromFile(file);

    chosenFile.add(uri);
    intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, chosenFile);
    activity.startActivity(Intent.createChooser(intent, "Condividi via..."));
}

From source file:arun.com.chromer.webheads.ui.context.WebHeadContextActivity.java

@OnClick(R.id.share_all)
public void onShareAllClick() {
    final CharSequence[] items = new String[] { getString(R.string.comma_seperated),
            getString(R.string.share_all_list) };
    new MaterialDialog.Builder(this).title(R.string.choose_share_method).items(items)
            .itemsCallbackSingleChoice(0, (dialog, itemView, which, text) -> {
                if (which == 0) {
                    startActivity(Intent.createChooser(
                            TEXT_SHARE_INTENT.putExtra(EXTRA_TEXT, getCSVUrls().toString()),
                            getString(R.string.share_all)));
                } else {
                    final ArrayList<Uri> webSites = new ArrayList<>();
                    for (Website website : websitesAdapter.getWebsites()) {
                        try {
                            webSites.add(Uri.parse(website.preferredUrl()));
                        } catch (Exception ignored) {
                        }//from  w w  w.j  a  v  a2  s.  co m
                    }
                    final Intent shareIntent = new Intent();
                    shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
                    shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, webSites);
                    shareIntent.setType("text/plain");
                    startActivity(Intent.createChooser(shareIntent, getString(R.string.share_all)));
                }
                return false;
            }).show();
}

From source file:foam.jellyfish.StarwispBuilder.java

public static void email(Context context, String emailTo, String emailCC, String subject, String emailText,
        List<String> filePaths) {
    //need to "send multiple" to get more than one attachment
    final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
    emailIntent.setType("text/plain");
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { emailTo });
    emailIntent.putExtra(android.content.Intent.EXTRA_CC, new String[] { emailCC });
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);

    ArrayList<String> extra_text = new ArrayList<String>();
    extra_text.add(emailText);//from   w w  w .j  av  a  2s . co  m
    emailIntent.putStringArrayListExtra(Intent.EXTRA_TEXT, extra_text);
    //emailIntent.putExtra(Intent.EXTRA_TEXT, emailText);

    //has to be an ArrayList
    ArrayList<Uri> uris = new ArrayList<Uri>();
    //convert from paths to Android friendly Parcelable Uri's
    for (String file : filePaths) {
        File fileIn = new File(file);
        Uri u = Uri.fromFile(fileIn);
        uris.add(u);
    }
    emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
    context.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}

From source file:org.gnucash.android.export.ExporterAsyncTask.java

/**
 * Starts an intent chooser to allow the user to select an activity to receive
 * the exported OFX file//from w w  w.j  a  va 2 s . co m
 * @param path String path to the file on disk
 */
private void shareFile(String path) {
    String defaultEmail = PreferenceManager.getDefaultSharedPreferences(mContext)
            .getString(mContext.getString(R.string.key_default_export_email), null);
    Intent shareIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
    shareIntent.setType("application/xml");
    ArrayList<Uri> exportFiles = new ArrayList<Uri>();
    if (mExportParams.getExportFormat() == ExportFormat.QIF) {
        try {
            List<String> splitFiles = splitQIF(new File(path), new File(path));
            for (String file : splitFiles) {
                exportFiles.add(Uri.parse("file://" + file));
            }
        } catch (IOException e) {
            Log.e(TAG, "error split up files in shareFile");
            e.printStackTrace();
            return;
        }
    } else {
        exportFiles.add(Uri.parse("file://" + path));
    }
    shareIntent.putExtra(Intent.EXTRA_STREAM, exportFiles);
    shareIntent.putExtra(Intent.EXTRA_SUBJECT,
            mContext.getString(R.string.title_export_email, mExportParams.getExportFormat().name()));
    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<CharSequence>();
    extraText.add(mContext.getString(R.string.description_export_email) + " "
            + formatter.format(new Date(System.currentTimeMillis())));
    shareIntent.putExtra(Intent.EXTRA_TEXT, extraText);

    mContext.startActivity(
            Intent.createChooser(shareIntent, mContext.getString(R.string.title_select_export_destination)));
}

From source file:com.jlcsoftware.callrecorder.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        Intent intent = new Intent(this, SettingsActivity.class);
        startActivity(intent);//from  w  w w.  jav  a  2  s.co  m
        return true;
    }

    if (id == R.id.action_save) {
        if (null != selectedItems && selectedItems.length > 0) {
            Runnable runnable = new Runnable() {
                @Override
                public void run() {
                    for (PhoneCallRecord record : selectedItems) {
                        record.getPhoneCall().setKept(true);
                        record.getPhoneCall().save(MainActivity.this);
                    }
                    LocalBroadcastManager.getInstance(MainActivity.this)
                            .sendBroadcast(new Intent(LocalBroadcastActions.NEW_RECORDING_BROADCAST)); // Causes refresh

                }
            };
            handler.post(runnable);
        }
        return true;
    }

    if (id == R.id.action_share) {
        if (null != selectedItems && selectedItems.length > 0) {
            Runnable runnable = new Runnable() {
                @Override
                public void run() {
                    ArrayList<Uri> fileUris = new ArrayList<Uri>();
                    for (PhoneCallRecord record : selectedItems) {
                        fileUris.add(Uri.fromFile(new File(record.getPhoneCall().getPathToRecording())));
                    }
                    Intent shareIntent = new Intent();
                    shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
                    shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, fileUris);
                    shareIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.email_title));
                    shareIntent.putExtra(Intent.EXTRA_HTML_TEXT,
                            Html.fromHtml(getString(R.string.email_body_html)));
                    shareIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.email_body));
                    shareIntent.setType("audio/*");
                    startActivity(Intent.createChooser(shareIntent, getString(R.string.action_share)));
                }
            };
            handler.post(runnable);
        }
        return true;
    }

    if (id == R.id.action_delete) {
        if (null != selectedItems && selectedItems.length > 0) {
            AlertDialog.Builder alert = new AlertDialog.Builder(this);
            alert.setTitle(R.string.delete_recording_title);
            alert.setMessage(R.string.delete_recording_subject);
            alert.setPositiveButton(R.string.dialog_yes, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {

                    Runnable runnable = new Runnable() {
                        @Override
                        public void run() {
                            Database callLog = Database.getInstance(MainActivity.this);
                            for (PhoneCallRecord record : selectedItems) {
                                int id = record.getPhoneCall().getId();
                                callLog.removeCall(id);
                            }

                            LocalBroadcastManager.getInstance(MainActivity.this).sendBroadcast(
                                    new Intent(LocalBroadcastActions.RECORDING_DELETED_BROADCAST));
                        }
                    };
                    handler.post(runnable);

                    dialog.dismiss();

                }
            });
            alert.setNegativeButton(R.string.dialog_no, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {

                    dialog.dismiss();
                }
            });

            alert.show();
        }
        return true;
    }

    if (id == R.id.action_delete_all) {

        AlertDialog.Builder alert = new AlertDialog.Builder(this);
        alert.setTitle(R.string.delete_recording_title);
        alert.setMessage(R.string.delete_all_recording_subject);
        alert.setPositiveButton(R.string.dialog_yes, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {

                Runnable runnable = new Runnable() {
                    @Override
                    public void run() {
                        Database.getInstance(MainActivity.this).removeAllCalls(false);
                        LocalBroadcastManager.getInstance(getApplicationContext())
                                .sendBroadcast(new Intent(LocalBroadcastActions.RECORDING_DELETED_BROADCAST));
                    }
                };
                handler.post(runnable);

                dialog.dismiss();

            }
        });
        alert.setNegativeButton(R.string.dialog_no, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {

                dialog.dismiss();
            }
        });

        alert.show();

        return true;
    }

    if (R.id.action_whitelist == id) {
        if (permissionReadContacts) {
            Intent intent = new Intent(this, WhitelistActivity.class);
            startActivity(intent);
        } else {
            AlertDialog.Builder alert = new AlertDialog.Builder(this);
            alert.setTitle(R.string.permission_whitelist_title);
            alert.setMessage(R.string.permission_whitelist);
        }
        return true;
    }
    if (R.id.action_about == id) {
        AboutDialog.show(this);
        return true;
    }

    return super.onOptionsItemSelected(item);
}

From source file:de.schildbach.wallet.ui.ReportIssueDialogBuilder.java

private void startSend(final CharSequence subject, final CharSequence text, final ArrayList<Uri> attachments) {
    final Intent intent;

    if (attachments.size() == 0) {
        intent = new Intent(Intent.ACTION_SEND);
        intent.setType("message/rfc822");
    } else if (attachments.size() == 1) {
        intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_STREAM, attachments.get(0));
    } else {//from  w w w  . j a v  a2  s  .co m
        intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
        intent.setType("text/plain");
        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachments);
    }

    intent.putExtra(Intent.EXTRA_EMAIL, new String[] { Constants.REPORT_EMAIL });
    if (subject != null)
        intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    intent.putExtra(Intent.EXTRA_TEXT, text);

    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

    try {
        context.startActivity(Intent.createChooser(intent,
                context.getString(R.string.report_issue_dialog_mail_intent_chooser)));
        log.info("invoked chooser for sending issue report");
    } catch (final Exception x) {
        Toast.makeText(context, R.string.report_issue_dialog_mail_intent_failed, Toast.LENGTH_LONG).show();
        log.error("report issue failed", x);
    }
}

From source file:com.jecelyin.android.file_explorer.FileExplorerAction.java

private void shareFile() {
    if (checkedList.isEmpty() || shareActionProvider == null)
        return;//ww  w  .ja v  a2  s .  co m

    Intent shareIntent = new Intent();
    if (checkedList.size() == 1) {
        File localFile = new File(checkedList.get(0).getPath());
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.setType(MimeTypes.getInstance().getMimeType(localFile.getPath()));
        shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(localFile));
    } else {
        shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);

        ArrayList<Uri> streams = new ArrayList<>();
        for (JecFile file : checkedList) {
            if (!(file instanceof LocalFile))
                throw new ExplorerException(
                        context.getString(R.string.can_not_share_x, file + " isn't LocalFile"));

            streams.add(Uri.fromFile(new File(file.getPath())));
        }

        shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, streams);
    }

    shareActionProvider.setShareIntent(shareIntent);
}

From source file:org.camlistore.UploadService.java

private void handleCommand(Intent intent) {
    Log.d(TAG, "in handleCommand() for onStart() intent: " + intent);
    if (intent == null) {
        stopServiceIfEmpty();/*  w ww  .  j  a  va 2s  .  c  o  m*/
        return;
    }

    String action = intent.getAction();
    if (Intent.ACTION_SEND.equals(action)) {
        handleSend(intent);
        return;
    }

    if (Intent.ACTION_SEND_MULTIPLE.equals(action)) {
        handleSendMultiple(intent);
        return;
    }

    if (INTENT_UPLOAD_ALL.equals(action)) {
        handleUploadAll();
        return;
    }

    try {
        if (mPrefs.autoUpload()) {
            boolean startAuto = false;
            boolean stopAuto = false;

            if (INTENT_POWER_CONNECTED.equals(action)) {
                if (!mPrefs.autoRequiresWifi() || WifiPowerReceiver.onWifi(this)) {
                    startAuto = true;
                }
            } else if (INTENT_NETWORK_WIFI.equals(action)) {
                if (!mPrefs.autoRequiresPower() || WifiPowerReceiver.onPower(this)) {
                    String ssid = "";
                    String requiredSSID = mPrefs.autoRequiredWifiSSID();
                    if (intent.hasExtra("SSID")) {
                        ssid = intent.getStringExtra("SSID");
                    }
                    Log.d(TAG, "SSID: '" + ssid + "' / Required SSID: '" + requiredSSID + "'");
                    if (requiredSSID.equals("") || requiredSSID.equals(ssid)) {
                        startAuto = true;
                    }
                }
            } else if (INTENT_POWER_DISCONNECTED.equals(action)) {
                stopAuto = mPrefs.autoRequiresPower();
            } else if (INTENT_NETWORK_NOT_WIFI.equals(action)) {
                stopAuto = mPrefs.autoRequiresWifi();
            }

            if (startAuto) {
                Log.d(TAG, "Starting automatic uploads");
                service.resume();
                handleUploadAll();
                return;
            }
            if (stopAuto) {
                Log.d(TAG, "Stopping automatic uploads");
                service.pause();
                stopBackgroundWatchers();
                return;
            }
        }
    } catch (RemoteException e) {
        // Ignore.
    }
}