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.nuvolect.securesuite.data.ExportVcf.java

public static void emailVcf(Activity act, long contact_id) {

    String messageTitle = "vCard for ";
    String messageBody = "\n\n\nContact from SecureSuite, a secure contact manager";

    try {/* w  ww . java  2s .  c om*/
        String displayName = SqlCipher.get(contact_id, ATab.display_name);
        String fileName = displayName.replaceAll("\\W+", "");
        if (fileName.isEmpty())
            fileName = "contact";
        fileName = fileName + ".vcf";

        new File(act.getFilesDir() + CConst.SHARE_FOLDER).mkdirs();
        File vcf_file = new File(act.getFilesDir() + CConst.SHARE_FOLDER + fileName);

        writeContactVcard(contact_id, vcf_file);

        // Must match "authorities" in Manifest provider definition
        String authorities = act.getResources().getString(R.string.app_authorities) + ".provider";

        Uri uri = null;
        try {
            uri = FileProvider.getUriForFile(act, authorities, vcf_file);
        } catch (IllegalArgumentException e) {
            LogUtil.logException(act, LogType.EXPORT_VCF, e);
        }

        //convert from paths to Android friendly Parcelable Uri's
        ArrayList<Uri> uris = new ArrayList<Uri>();
        uris.add(uri);

        Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_SUBJECT, messageTitle + displayName);
        intent.putExtra(Intent.EXTRA_TEXT, messageBody);
        intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.putExtra("path", vcf_file.getAbsolutePath());

        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
        act.startActivityForResult(Intent.createChooser(intent, "Share with..."),
                CConst.RESPONSE_CODE_SHARE_VCF);

    } catch (Exception e) {
        LogUtil.logException(act, LogType.EXPORT_VCF, e);
    }
}

From source file:info.schnatterer.logbackandroiddemo.SendLogActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    /* Get URIs for log files using android.support.v4.content.FileProvider */
    ArrayList<Uri> uris = new ArrayList<>();
    for (final File fileEntry : Logs.getLogFiles(this)) {
        // Don't recurse!
        if (!fileEntry.isDirectory()) {
            // Create content provider URI
            uris.add(FileProvider.getUriForFile(this, getString(R.string.authority_log_file_provider),
                    fileEntry));/*from   ww w .  ja v a  2  s  .  c o m*/
        }
    }

    final Intent email = new Intent(Intent.ACTION_SEND_MULTIPLE);
    email.setType("message/rfc822");
    email.putExtra(Intent.EXTRA_EMAIL, new String[] { "a@b.c" });
    email.putExtra(Intent.EXTRA_SUBJECT, getString(getApplicationInfo().labelRes));
    email.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
    email.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    startActivity(email);

    finish();
}

From source file:ee.ria.DigiDoc.activity.OpenExternalFileActivity.java

private void handleIntentAction() {
    Intent intent = getIntent();// w w w. ja va  2 s.  c o  m
    ContainerFacade container = null;
    Timber.d("Handling action: %s ", intent.getAction());
    switch (intent.getAction()) {
    case Intent.ACTION_VIEW:
        try {
            container = createContainer(intent.getData());
        } catch (Exception e) {
            Timber.e(e, "Error creating container from uri %s", intent.getData().toString());
        }
        break;
    case Intent.ACTION_SEND:
        Uri sendUri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
        if (sendUri != null) {
            container = createContainer(sendUri);
        }
        break;
    case Intent.ACTION_SEND_MULTIPLE:
        ArrayList<Uri> uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
        if (uris != null) {
            container = createContainer(uris);
        }
        break;
    }

    if (container != null) {
        createContainerDetailsFragment(container);
    } else {
        createErrorFragment();
    }
}

From source file:org.apache.cordova.EmailComposer.java

private void sendEmail(JSONObject parameters) {

    final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);

    // String callback = parameters.getString("callback");
    System.out.println(parameters.toString());

    boolean isHTML = false;
    try {/*w  w  w  . j  a v  a 2  s.  c o  m*/
        isHTML = parameters.getBoolean("bIsHTML");
    } catch (Exception e) {
        LOG.e("EmailComposer", "Error handling isHTML param: " + e.toString());
    }

    if (isHTML) {
        emailIntent.setType("text/html");
    } else {
        emailIntent.setType("text/plain");
    }

    // setting subject
    try {
        String subject = parameters.getString("subject");
        if (subject != null && subject.length() > 0) {
            emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
        }
    } catch (Exception e) {
        LOG.e("EmailComposer", "Error handling subject param: " + e.toString());
    }

    // setting body
    try {
        String body = parameters.getString("body");
        if (body != null && body.length() > 0) {
            if (isHTML) {
                emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(body));
            } else {
                emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
            }
        }
    } catch (Exception e) {
        LOG.e("EmailComposer", "Error handling body param: " + e.toString());
    }

    // setting TO recipients
    try {
        JSONArray toRecipients = parameters.getJSONArray("toRecipients");
        if (toRecipients != null && toRecipients.length() > 0) {
            String[] to = new String[toRecipients.length()];
            for (int i = 0; i < toRecipients.length(); i++) {
                to[i] = toRecipients.getString(i);
            }
            emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, to);
        }
    } catch (Exception e) {
        LOG.e("EmailComposer", "Error handling toRecipients param: " + e.toString());
    }

    // setting CC recipients
    try {
        JSONArray ccRecipients = parameters.getJSONArray("ccRecipients");
        if (ccRecipients != null && ccRecipients.length() > 0) {
            String[] cc = new String[ccRecipients.length()];
            for (int i = 0; i < ccRecipients.length(); i++) {
                cc[i] = ccRecipients.getString(i);
            }
            emailIntent.putExtra(android.content.Intent.EXTRA_CC, cc);
        }
    } catch (Exception e) {
        LOG.e("EmailComposer", "Error handling ccRecipients param: " + e.toString());
    }

    // setting BCC recipients
    try {
        JSONArray bccRecipients = parameters.getJSONArray("bccRecipients");
        if (bccRecipients != null && bccRecipients.length() > 0) {
            String[] bcc = new String[bccRecipients.length()];
            for (int i = 0; i < bccRecipients.length(); i++) {
                bcc[i] = bccRecipients.getString(i);
            }
            emailIntent.putExtra(android.content.Intent.EXTRA_BCC, bcc);
        }
    } catch (Exception e) {
        LOG.e("EmailComposer", "Error handling bccRecipients param: " + e.toString());
    }

    // setting attachments
    try {
        JSONArray attachments = parameters.getJSONArray("attachments");
        if (attachments != null && attachments.length() > 0) {
            ArrayList<Uri> uris = new ArrayList<Uri>();
            // convert from paths to Android friendly Parcelable Uri's
            for (int i = 0; i < attachments.length(); i++) {
                try {
                    File file = new File(attachments.getString(i));
                    if (file.exists()) {
                        Uri uri = Uri.fromFile(file);
                        uris.add(uri);
                    }
                } catch (Exception e) {
                    LOG.e("EmailComposer", "Error adding an attachment: " + e.toString());
                }
            }
            if (uris.size() > 0) {
                emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
            }
        }
    } catch (Exception e) {
        LOG.e("EmailComposer", "Error handling attachments param: " + e.toString());
    }

    this.cordova.startActivityForResult(this, emailIntent, 0);
}

From source file:de.appplant.cordova.plugin.emailcomposer.EmailComposer.java

/**
 * Erstellt den ViewController fr Mails und fgt die bergebenen Eigenschaften ein.
 *
 * @param {JSONObject} params (Subject, Body, Recipients, ...)
 *//*from  w  ww  .  j  a  v a2s  .  co  m*/
private Intent getDraftWithProperties(JSONObject params) throws JSONException {
    Intent mail = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);

    if (params.has("subject"))
        setSubject(params.getString("subject"), mail);
    if (params.has("body"))
        setBody(params.getString("body"), params.optBoolean("isHtml"), mail);
    if (params.has("to"))
        setRecipients(params.getJSONArray("to"), mail);
    if (params.has("cc"))
        setCcRecipients(params.getJSONArray("cc"), mail);
    if (params.has("bcc"))
        setBccRecipients(params.getJSONArray("bcc"), mail);
    if (params.has("attachments"))
        setAttachments(params.getJSONArray("attachments"), mail);

    mail.setType("application/octet-stream");

    return mail;
}

From source file:org.kde.kdeconnect.Plugins.SharePlugin.ShareActivity.java

private void updateComputerList() {

    final Intent intent = getIntent();

    String action = intent.getAction();
    if (!Intent.ACTION_SEND.equals(action) && !Intent.ACTION_SEND_MULTIPLE.equals(action)) {
        finish();/*from   w ww.  ja v  a 2 s.c  o m*/
        return;
    }

    BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
        @Override
        public void onServiceStart(final BackgroundService service) {

            Collection<Device> devices = service.getDevices().values();
            final ArrayList<Device> devicesList = new ArrayList<>();
            final ArrayList<ListAdapter.Item> items = new ArrayList<>();

            items.add(new SectionItem(getString(R.string.share_to)));

            for (Device d : devices) {
                if (d.isReachable() && d.isPaired()) {
                    devicesList.add(d);
                    items.add(new EntryItem(d.getName()));
                }
            }

            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    ListView list = (ListView) findViewById(R.id.listView1);
                    list.setAdapter(new ListAdapter(ShareActivity.this, items));
                    list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

                            Device device = devicesList.get(i - 1); //NOTE: -1 because of the title!

                            Bundle extras = intent.getExtras();
                            if (extras != null) {
                                if (extras.containsKey(Intent.EXTRA_STREAM)) {

                                    try {

                                        ArrayList<Uri> uriList;
                                        if (!Intent.ACTION_SEND.equals(intent.getAction())) {
                                            uriList = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
                                        } else {
                                            Uri uri = extras.getParcelable(Intent.EXTRA_STREAM);
                                            uriList = new ArrayList<>();
                                            uriList.add(uri);
                                        }

                                        SharePlugin.queuedSendUriList(getApplicationContext(), device, uriList);

                                    } catch (Exception e) {
                                        Log.e("ShareActivity", "Exception");
                                        e.printStackTrace();
                                    }

                                } else if (extras.containsKey(Intent.EXTRA_TEXT)) {
                                    String text = extras.getString(Intent.EXTRA_TEXT);
                                    String subject = extras.getString(Intent.EXTRA_SUBJECT);

                                    //Hack: Detect shared youtube videos, so we can open them in the browser instead of as text
                                    if (subject != null && subject.endsWith("YouTube")) {
                                        int index = text.indexOf(": http://youtu.be/");
                                        if (index > 0) {
                                            text = text.substring(index + 2); //Skip ": "
                                        }
                                    }

                                    boolean isUrl;
                                    try {
                                        new URL(text);
                                        isUrl = true;
                                    } catch (Exception e) {
                                        isUrl = false;
                                    }
                                    NetworkPackage np = new NetworkPackage(
                                            SharePlugin.PACKAGE_TYPE_SHARE_REQUEST);
                                    if (isUrl) {
                                        np.set("url", text);
                                    } else {
                                        np.set("text", text);
                                    }
                                    device.sendPackage(np);
                                }
                            }
                            finish();
                        }
                    });
                }
            });

        }
    });
}

From source file:com.android.shell.BugreportReceiver.java

/**
 * Build {@link Intent} that can be used to share the given bugreport.
 *//*from  w  w w.  j ava2  s .  c  om*/
private static Intent buildSendIntent(Context context, Uri bugreportUri, Uri screenshotUri) {
    final Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setType("application/vnd.android.bugreport");

    intent.putExtra(Intent.EXTRA_SUBJECT, bugreportUri.getLastPathSegment());
    intent.putExtra(Intent.EXTRA_TEXT, SystemProperties.get("ro.build.description"));

    final ArrayList<Uri> attachments = Lists.newArrayList(bugreportUri, screenshotUri);
    intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachments);

    final Account sendToAccount = findSendToAccount(context);
    if (sendToAccount != null) {
        intent.putExtra(Intent.EXTRA_EMAIL, new String[] { sendToAccount.name });
    }

    return intent;
}

From source file:de.appplant.cordova.emailcomposer.EmailComposerImpl.java

/**
 * The intent with the containing email properties.
 *
 * @param params//from w ww. j a  v  a 2 s.  com
 * The email properties like subject or body
 * @param ctx
 * The context of the application.
 * @return
 * The resulting intent.
 * @throws JSONException
 */
public Intent getDraftWithProperties(JSONObject params, Context ctx) throws JSONException {

    Intent mail = new Intent(Intent.ACTION_SEND_MULTIPLE);
    String app = params.optString("app", null);

    if (params.has("subject"))
        setSubject(params.getString("subject"), mail);
    if (params.has("body"))
        setBody(params.getString("body"), params.optBoolean("isHtml"), mail);
    if (params.has("to"))
        setRecipients(params.getJSONArray("to"), mail);
    if (params.has("cc"))
        setCcRecipients(params.getJSONArray("cc"), mail);
    if (params.has("bcc"))
        setBccRecipients(params.getJSONArray("bcc"), mail);
    if (params.has("attachments"))
        setAttachments(params.getJSONArray("attachments"), mail, ctx);

    if (!app.equals(MAILTO_SCHEME) && isAppInstalled(app, ctx)) {
        mail.setPackage(app);
    }

    mail.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    return mail;
}

From source file:org.telegram.ui.LaunchActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ApplicationLoader.postInitApplication();

    this.setTheme(R.style.Theme_TMessages);
    getWindow().setBackgroundDrawableResource(R.drawable.transparent);
    getWindow().setFormat(PixelFormat.RGB_565);

    if (!UserConfig.clientActivated) {
        Intent intent = getIntent();// www  .j a  va2  s  . com
        if (intent != null && intent.getAction() != null && Intent.ACTION_SEND.equals(intent.getAction())
                || intent.getAction().equals(Intent.ACTION_SEND_MULTIPLE)) {
            finish();
            return;
        }
        Intent intent2 = new Intent(this, IntroActivity.class);
        startActivity(intent2);
        finish();
        return;
    }

    int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
    if (resourceId > 0) {
        Utilities.statusBarHeight = getResources().getDimensionPixelSize(resourceId);
    }

    NotificationCenter.getInstance().postNotificationName(702, this);
    currentConnectionState = ConnectionsManager.getInstance().connectionState;
    for (BaseFragment fragment : ApplicationLoader.fragmentsStack) {
        if (fragment.fragmentView != null) {
            ViewGroup parent = (ViewGroup) fragment.fragmentView.getParent();
            if (parent != null) {
                parent.removeView(fragment.fragmentView);
            }
            fragment.fragmentView = null;
        }
        fragment.parentActivity = this;
    }
    setContentView(R.layout.application_layout);
    NotificationCenter.getInstance().addObserver(this, 1234);
    NotificationCenter.getInstance().addObserver(this, 658);
    NotificationCenter.getInstance().addObserver(this, 701);
    NotificationCenter.getInstance().addObserver(this, 702);
    NotificationCenter.getInstance().addObserver(this, 703);
    NotificationCenter.getInstance().addObserver(this, GalleryImageViewer.needShowAllMedia);
    getSupportActionBar().setLogo(R.drawable.ab_icon_fixed2);

    statusView = getLayoutInflater().inflate(R.layout.updating_state_layout, null);
    statusBackground = statusView.findViewById(R.id.back_button_background);
    backStatusButton = statusView.findViewById(R.id.back_button);
    containerView = findViewById(R.id.container);
    statusText = (TextView) statusView.findViewById(R.id.status_text);
    statusBackground.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (ApplicationLoader.fragmentsStack.size() > 1) {
                onBackPressed();
            }
        }
    });

    if (ApplicationLoader.fragmentsStack.isEmpty()) {
        MessagesActivity fragment = new MessagesActivity();
        fragment.onFragmentCreate();
        ApplicationLoader.fragmentsStack.add(fragment);
    }

    handleIntent(getIntent(), false, savedInstanceState != null);
}

From source file:com.dynamixsoftware.printingsample.ShareIntentFragment.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.share_image_action_view: {
        String imageFilePath = FilesUtils.getFilePath(requireContext(), FilesUtils.FILE_PNG);
        Log.i("testtest", Uri.parse("file://" + imageFilePath).toString());

        if (imageFilePath != null) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.parse("file://" + imageFilePath), "image/png");
            if (startPrintHandActivityFailed(intent))
                showStartPrintHandActivityErrorDialog();
        } else/*from w w w .  jav  a  2 s . c om*/
            showOpenFileErrorDialog();
        break;
    }
    case R.id.share_image_action_send: {
        String imageFilePath = FilesUtils.getFilePath(requireContext(), FilesUtils.FILE_PNG);
        if (imageFilePath != null) {
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("image/png");
            intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + imageFilePath));
            if (startPrintHandActivityFailed(intent))
                showStartPrintHandActivityErrorDialog();
        } else
            showOpenFileErrorDialog();
        break;
    }
    case R.id.share_image_multiple: {
        String imageFilePath = FilesUtils.getFilePath(requireContext(), FilesUtils.FILE_PNG);
        if (imageFilePath != null) {
            Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
            Uri uri = Uri.parse("file://" + imageFilePath);
            ArrayList<Uri> urisList = new ArrayList<>();
            urisList.add(uri);
            urisList.add(uri);
            urisList.add(uri);
            intent.putExtra(Intent.EXTRA_STREAM, urisList);
            intent.setType("image/*");
            if (startPrintHandActivityFailed(intent))
                showStartPrintHandActivityErrorDialog();
        } else {
            showOpenFileErrorDialog();
        }
        break;
    }
    case R.id.share_image_return: {
        String imageFilePath = FilesUtils.getFilePath(requireContext(), FilesUtils.FILE_PNG);
        if (imageFilePath != null) {
            Intent intent = new Intent(Intent.ACTION_VIEW); // can be ACTION_SEND - see share_image_action_send for properly configure intent
            intent.setDataAndType(Uri.parse("file://" + imageFilePath), "image/png");
            if (startPrintHandActivityForResultFailed(intent, REQUEST_CODE_IMAGE))
                showStartPrintHandActivityErrorDialog();
        } else
            showOpenFileErrorDialog();
        break;
    }
    case R.id.share_file: {
        String docFilePath = FilesUtils.getFilePath(requireContext(), FilesUtils.FILE_DOC);
        if (docFilePath != null) {
            Intent intent = new Intent(Intent.ACTION_VIEW); // can be ACTION_SEND - see share_image_action_send for properly configure intent
            intent.setDataAndType(Uri.parse("file://" + docFilePath), "application/msword"); // scheme "content://" also available
            // MIME types available:
            // application/pdf
            // application/vnd.ms-word
            // application/ms-word
            // application/msword
            // application/vnd.openxmlformats-officedocument.wordprocessingml.document
            // application/vnd.ms-excel
            // application/ms-excel
            // application/msexcel
            // application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
            // application/vnd.ms-powerpoint
            // application/ms-powerpoint
            // application/mspowerpoint
            // application/vnd.openxmlformats-officedocument.presentationml.presentation
            // application/haansofthwp
            // text/plain
            // text/html
            if (startPrintHandActivityFailed(intent))
                showStartPrintHandActivityErrorDialog();
        } else
            showOpenFileErrorDialog();
        break;
    }
    case R.id.share_web_page_uri: {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.parse("http://printhand.com"), "text/html"); // worked only 'http' - bug in PrintHand?
        if (startPrintHandActivityFailed(intent))
            showStartPrintHandActivityErrorDialog();
        break;
    }
    case R.id.share_web_page_string: {
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/html");
        intent.putExtra(Intent.EXTRA_TEXT, "https://printhand.com");
        if (startPrintHandActivityFailed(intent))
            showStartPrintHandActivityErrorDialog();
        break;
    }
    case R.id.activate_license: {
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.putExtra(Intent.EXTRA_TEXT, "YOUR_KEY_HERE"); // put your activation key here
        intent.setType("text/license");
        intent.putExtra("showErrorMessage", true); // if true PrintHand shown error message
        intent.putExtra("return", false); // if true (and showErrorMessage is false) PrintHand provide result to your onActivityResult
        if (startPrintHandActivityFailed(intent))
            showStartPrintHandActivityErrorDialog();
        break;
    }
    case R.id.activate_license_return: {
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.putExtra(Intent.EXTRA_TEXT, "YOUR_KEY_HERE"); // put your activation key here
        intent.setType("text/license");
        intent.putExtra("showErrorMessage", false); // if true PrintHand shown error message
        intent.putExtra("return", true); // if true (and showErrorMessage is false) PrintHand provide result to your onActivityResult
        if (startPrintHandActivityForResultFailed(intent, REQUEST_CODE_LICENSE))
            showStartPrintHandActivityErrorDialog();
        break;
    }
    }
}