Java Code Examples for android.content.Intent#ACTION_SEND_MULTIPLE

The following examples show how to use android.content.Intent#ACTION_SEND_MULTIPLE . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private void sendLogs() {
    try {
        ArrayList<Uri> uris = new ArrayList<>();
        File sdCard = ApplicationLoader.applicationContext.getExternalFilesDir(null);
        File dir = new File(sdCard.getAbsolutePath() + "/logs");
        File[] files = dir.listFiles();

        for (File file : files) {
            if (Build.VERSION.SDK_INT >= 24) {
                uris.add(FileProvider.getUriForFile(getParentActivity(), BuildConfig.APPLICATION_ID + ".provider", file));
            } else {
                uris.add(Uri.fromFile(file));
            }
        }

        if (uris.isEmpty()) {
            return;
        }
        Intent i = new Intent(Intent.ACTION_SEND_MULTIPLE);
        if (Build.VERSION.SDK_INT >= 24) {
            i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        }
        i.setType("message/rfc822");
        i.putExtra(Intent.EXTRA_EMAIL, "");
        i.putExtra(Intent.EXTRA_SUBJECT, "last logs");
        i.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
        getParentActivity().startActivityForResult(Intent.createChooser(i, "Select email application."), 500);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 2
Source Project: QtAndroidTools   File: AndroidTools.java    License: MIT License 6 votes vote down vote up
public int getActivityAction()
{
    final String ActionValue = mActivityInstance.getIntent().getAction();
    int ActionId = ACTION_NONE;

    if(ActionValue != null)
    {
        switch(ActionValue)
        {
            case Intent.ACTION_SEND:
                ActionId = ACTION_SEND;
                break;
            case Intent.ACTION_SEND_MULTIPLE:
                ActionId = ACTION_SEND_MULTIPLE;
                break;
            case Intent.ACTION_PICK:
                ActionId = ACTION_PICK;
                break;
        }
    }

    return ActionId;
}
 
Example 3
public static void sendFiles(Context context, ArrayList<Uri> uris, String mime, ClipData clipData)
{
	if(uris == null || uris.isEmpty())
		return;

	Intent actionIntent = new Intent(uris.size() > 1 ? Intent.ACTION_SEND_MULTIPLE : Intent.ACTION_SEND);
	actionIntent.setType(mime == null ? "*/*" : mime);
	if (uris.size() > 1)
		actionIntent.putExtra(Intent.EXTRA_STREAM, uris);
	else
		actionIntent.putExtra(Intent.EXTRA_STREAM, uris.get(0));
	if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && clipData!=null)
	{
		actionIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
		actionIntent.setClipData(clipData);
	}

	Intent startIntent = Intent.createChooser(actionIntent, context.getString(R.string.send_files_to));
	startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
	context.startActivity(startIntent);
}
 
Example 4
private Intent getEmailIntent() {
    Intent emailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
    String developerEmail = context.getString(R.string.about_developer_email);
    emailIntent.setData(Uri.fromParts("mailto", developerEmail, null));
    emailIntent.setType("text/plain");
    emailIntent.setType("message/rfc822");
    emailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] {developerEmail});
    if (!TextUtils.isEmpty(userMessage)) {
        emailIntent.putExtra(Intent.EXTRA_TEXT, userMessage);
    }
    emailIntent.putExtra(
        Intent.EXTRA_SUBJECT,
        context.getString(
            TextUtils.isEmpty(stackTrace) ? R.string.email_subject_feedback : R.string.email_subject_crash_report,
            BuildConfig.APPLICATION_ID,
            BuildConfig.VERSION_NAME
        )
    );
    ArrayList<Uri> uris = new ArrayList<>();
    for (File file: files) {
        uris.add(getUri(file));
    }
    emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
    return emailIntent;
}
 
Example 5
Source Project: openlauncher   File: ShareUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Share the given files as stream with given mime-type
 *
 * @param files    The files to share
 * @param mimeType The files mime type. Usally * / * is the best option
 */
public boolean shareStreamMultiple(final Collection<File> files, final String mimeType) {
    ArrayList<Uri> uris = new ArrayList<>();
    for (File file : files) {
        File uri = new File(file.toString());
        uris.add(FileProvider.getUriForFile(_context, getFileProviderAuthority(), file));
    }

    try {
        Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
        intent.setType(mimeType);
        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
        showChooser(intent, null);
        return true;
    } catch (Exception e) { // FileUriExposed(API24) / IllegalArgument
        return false;
    }
}
 
Example 6
@Override
protected void onPostExecute(ArrayList<Uri> uris) {
    if (progressDialog != null) {
        progressDialog.dismiss();
    }

    if (uris.size() != observation.getAttachments().size()) {
        Toast toast = Toast.makeText(activity, "One or more attachments failed to attach", Toast.LENGTH_LONG);
        toast.show();
    }

    Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_SUBJECT, observation.getEvent().getName() + " MAGE Observation");
    intent.putExtra(Intent.EXTRA_TEXT, observationText(observation));
    intent.putExtra(Intent.EXTRA_STREAM, uris);
    activity.startActivity(Intent.createChooser(intent, "Share Observation"));
}
 
Example 7
private void sendLogs() {
    try {
        ArrayList<Uri> uris = new ArrayList<>();
        File sdCard = ApplicationLoader.applicationContext.getExternalFilesDir(null);
        File dir = new File(sdCard.getAbsolutePath() + "/logs");
        File[] files = dir.listFiles();

        for (File file : files) {
            if (Build.VERSION.SDK_INT >= 24) {
                uris.add(FileProvider.getUriForFile(getParentActivity(), BuildConfig.APPLICATION_ID + ".provider", file));
            } else {
                uris.add(Uri.fromFile(file));
            }
        }

        if (uris.isEmpty()) {
            return;
        }
        Intent i = new Intent(Intent.ACTION_SEND_MULTIPLE);
        if (Build.VERSION.SDK_INT >= 24) {
            i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        }
        i.setType("message/rfc822");
        i.putExtra(Intent.EXTRA_EMAIL, "");
        i.putExtra(Intent.EXTRA_SUBJECT, "last logs");
        i.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
        getParentActivity().startActivityForResult(Intent.createChooser(i, "Select email application."), 500);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 8
private static void sendEmailWithError(Context activityContext, EmailErrorReport emailErrorReport) {
    Intent sendEmail = new Intent(Intent.ACTION_SEND_MULTIPLE);
    sendEmail.setType("message/rfc822");

    emailErrorReport.configureRecipients(sendEmail);
    emailErrorReport.configureSubject(sendEmail);
    emailErrorReport.configureMessage(sendEmail);
    emailErrorReport.configureAttachments(sendEmail, activityContext);

    try {
        activityContext.startActivity(Intent.createChooser(sendEmail, "Send mail..."));
    } catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(activityContext, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
    }
}
 
Example 9
Source Project: fitnotifications   File: DebugLog.java    License: Apache License 2.0 5 votes vote down vote up
public Intent emailLogIntent(Context context, String logcat) {
    Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
    intent.setType("application/octet-stream");

    String subject = "Fit Notification Logs";
    ArrayList<Uri> attachments = new ArrayList<>();
    attachments.add(FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".provider", mLogFile));
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "[email protected]" });
    intent.putExtra(Intent.EXTRA_TEXT, logcat);
    intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachments);

    return intent;
}
 
Example 10
private void shareEvent ()
{
    String title = "Phoneypot: " + mEvent.getStartTime().toLocaleString();

    //need to "send multiple" to get more than one attachment
    final Intent emailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
    emailIntent.setType("text/plain");

    emailIntent.putExtra(Intent.EXTRA_SUBJECT, title);
    emailIntent.putExtra(Intent.EXTRA_TEXT, generateLog());
    //has to be an ArrayList
    ArrayList<Uri> uris = new ArrayList<>();
    //convert from paths to Android friendly Parcelable Uri's
    for (EventTrigger trigger : eventTriggerList)
    {
        // ignore triggers for which we do not have valid file/file-paths
        if (trigger.getMimeType() == null || trigger.getPath() == null)
            continue;

        File fileIn = new File(trigger.getPath());
        Uri u = Uri.fromFile(fileIn);
        uris.add(u);
    }

    emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
    startActivity(Intent.createChooser(emailIntent, getString(R.string.share_event_action)));
}
 
Example 11
private void shareProject() {
    String savedFilePath;
    savedFilePath = saveProject();
    if (savedFilePath == null || savedFilePath.length() == 0) {
        return;
    }
    Uri fileUri = Uri.fromFile(new File(savedFilePath));
    ArrayList<Uri> uris = new ArrayList<>();
    Intent sendIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
    sendIntent.setType("application/zip");
    uris.add(fileUri);
    sendIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
    startActivity(Intent.createChooser(sendIntent, null));
}
 
Example 12
Source Project: AndroidUtilCode   File: IntentUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Return the intent of share images.
 *
 * @param content The content.
 * @param uris    The uris of image.
 * @return the intent of share image
 */
public static Intent getShareImageIntent(final String content, final ArrayList<Uri> uris) {
    Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
    intent.putExtra(Intent.EXTRA_TEXT, content);
    intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
    intent.setType("image/*");
    return getIntent(intent, true);
}
 
Example 13
Source Project: EasyFeedback   File: FeedbackActivity.java    License: Apache License 2.0 5 votes vote down vote up
public void sendEmail(String body) {

        Intent emailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
        emailIntent.setType("text/plain");
        emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{emailId});
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.feedback_mail_subject, getAppLabel()));
        emailIntent.putExtra(Intent.EXTRA_TEXT, body);

        ArrayList<Uri> uris = new ArrayList<>();


        if (withInfo) {
            Uri deviceInfoUri = createFileFromString(deviceInfo, getString(R.string.file_name_device_info));
            uris.add(deviceInfoUri);

            Uri logUri = createFileFromString(LOG_TO_STRING, getString(R.string.file_name_device_log));
            uris.add(logUri);
        }

        if (realPath != null) {
            Uri uri = FileProvider.getUriForFile(
                    this,
                    getApplicationContext()
                            .getPackageName() + ".provider", new File(realPath));
            //Uri uri = Uri.parse("file://" + realPath);
            uris.add(uri);
        }
        emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
        emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        startActivity(Utils.createEmailOnlyChooserIntent(this, emailIntent, getString(R.string.send_feedback_two)));
    }
 
Example 14
public void shareImages() {

        final Intent shareIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
        shareIntent.setType("image/jpg");

        ArrayList<Uri> filesUris = new ArrayList<>();

        for (String i : myThumbAdapter.getSelectedFiles() ) {
            filesUris.add(Uri.parse("file://" + i));
        }
        shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, filesUris);

        startActivity(Intent.createChooser(shareIntent, getString(R.string.share_snackbar)));
    }
 
Example 15
Source Project: telescope   File: EmailLens.java    License: Apache License 2.0 5 votes vote down vote up
@Override protected Intent doInBackground(Void... params) {
  Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
  intent.setType("message/rfc822");

  if (subject != null) {
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
  }

  if (addresses != null) {
    intent.putExtra(Intent.EXTRA_EMAIL, addresses);
  }

  String body = getBody();
  if (body != null) {
    intent.putExtra(Intent.EXTRA_TEXT, body);
  }

  Set<Uri> additionalAttachments = getAdditionalAttachments();
  ArrayList<Uri> attachments = new ArrayList<>(additionalAttachments.size() + 1 /* screen */);
  if (!additionalAttachments.isEmpty()) {
    attachments.addAll(additionalAttachments);
  }
  if (screenshot != null) {
    attachments.add(TelescopeFileProvider.getUriForFile(context, screenshot));
  }

  if (!attachments.isEmpty()) {
    intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachments);
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
  }

  return intent;
}
 
Example 16
Source Project: debugdrawer   File: BugReportLens.java    License: Apache License 2.0 4 votes vote down vote up
private void submitReport(Report report, File logs) {
	DisplayMetrics dm = context.getResources().getDisplayMetrics();
	String densityBucket = getDensityString(dm);

	Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
	intent.setType("message/rfc822");
	// TODO: intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "[email protected]" });
	intent.putExtra(Intent.EXTRA_SUBJECT, report.title);

	StringBuilder body = new StringBuilder();
	if (!Strings.isBlank(report.description)) {
		body.append("{panel:title=Description}\n").append(report.description).append("\n{panel}\n\n");
	}

	// TODO: Change to dyanimic BuildConfig
	body.append("{panel:title=App}\n");
	body.append("Version: ").append(BuildConfig.VERSION_NAME).append('\n');
	body.append("Version code: ").append(BuildConfig.VERSION_CODE).append('\n');
	body.append("{panel}\n\n");

	body.append("{panel:title=Device}\n");
	body.append("Make: ").append(Build.MANUFACTURER).append('\n');
	body.append("Model: ").append(Build.MODEL).append('\n');
	body.append("Resolution: ")
			.append(dm.heightPixels)
			.append("x")
			.append(dm.widthPixels)
			.append('\n');
	body.append("Density: ")
			.append(dm.densityDpi)
			.append("dpi (")
			.append(densityBucket)
			.append(")\n");
	body.append("Release: ").append(Build.VERSION.RELEASE).append('\n');
	body.append("API: ").append(Build.VERSION.SDK_INT).append('\n');
	body.append("{panel}");

	intent.putExtra(Intent.EXTRA_TEXT, body.toString());

	ArrayList<Uri> attachments = new ArrayList<>();
	if (screenshot != null && report.includeScreenshot) {
		attachments.add(Uri.fromFile(screenshot));
	}
	if (logs != null) {
		attachments.add(Uri.fromFile(logs));
	}

	if (!attachments.isEmpty()) {
		intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachments);
	}

	Intents.maybeStartActivity(context, intent);
}
 
Example 17
Source Project: u2020-mvp   File: BugReportLens.java    License: Apache License 2.0 4 votes vote down vote up
private void submitReport(BugReportView.Report report, File logs) {
    DisplayMetrics dm = context.getResources().getDisplayMetrics();
    String densityBucket = getDensityString(dm);

    Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
    intent.setType("message/rfc822");
    // TODO: intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "[email protected]" });
    intent.putExtra(Intent.EXTRA_SUBJECT, report.title);

    StringBuilder body = new StringBuilder();
    if (!Strings.isBlank(report.description)) {
        body.append("{panel:title=Description}\n").append(report.description).append("\n{panel}\n\n");
    }

    body.append("{panel:title=App}\n");
    body.append("Version: ").append(BuildConfig.VERSION_NAME).append('\n');
    body.append("Version code: ").append(BuildConfig.VERSION_CODE).append('\n');
    body.append("{panel}\n\n");

    body.append("{panel:title=Device}\n");
    body.append("Make: ").append(Build.MANUFACTURER).append('\n');
    body.append("Model: ").append(Build.MODEL).append('\n');
    body.append("Resolution: ")
            .append(dm.heightPixels)
            .append("x")
            .append(dm.widthPixels)
            .append('\n');
    body.append("Density: ")
            .append(dm.densityDpi)
            .append("dpi (")
            .append(densityBucket)
            .append(")\n");
    body.append("Release: ").append(Build.VERSION.RELEASE).append('\n');
    body.append("API: ").append(Build.VERSION.SDK_INT).append('\n');
    body.append("{panel}");

    intent.putExtra(Intent.EXTRA_TEXT, body.toString());

    ArrayList<Uri> attachments = new ArrayList<>();
    if (screenshot != null && report.includeScreenshot) {
        attachments.add(Uri.fromFile(screenshot));
    }
    if (logs != null) {
        attachments.add(Uri.fromFile(logs));
    }

    if (!attachments.isEmpty()) {
        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachments);
    }

    Intents.maybeStartActivity(context, intent);
}
 
Example 18
Source Project: explorer   File: MainActivity.java    License: Apache License 2.0 4 votes vote down vote up
private void actionSend() {

        Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);

        intent.setType("*/*");

        ArrayList<Uri> uris = new ArrayList<>();

        for (File file : adapter.getSelectedItems()) {

            if (file.isFile()) uris.add(Uri.fromFile(file));
        }

        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);

        startActivity(intent);
    }
 
Example 19
private void sendFeedback() {
  if (isContentValid()) {
    Intent emailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
    emailIntent.setType("message/rfc822");

    final AptoideApplication application =
        (AptoideApplication) getContext().getApplicationContext();
    emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] {
        application.getFeedbackEmail()
    });
    final String cachePath = getContext().getApplicationContext()
        .getCacheDir()
        .getPath();
    unManagedSubscription = installedRepository.getInstalled(getContext().getPackageName())
        .first()
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(installed1 -> {
          String versionName = "";
          if (installed1 != null) {
            versionName = installed1.getVersionName();
          }

          emailIntent.putExtra(Intent.EXTRA_SUBJECT,
              "[Feedback]-" + versionName + ": " + subgectEdit.getText()
                  .toString());
          emailIntent.putExtra(Intent.EXTRA_TEXT, messageBodyEdit.getText()
              .toString());
          //attach screenshots and logs
          if (logsAndScreenshotsCb.isChecked()) {
            ArrayList<Uri> uris = new ArrayList<Uri>();
            if (screenShotPath != null) {
              File ss = new File(screenShotPath);
              uris.add(getUriFromFile(ss));
            }
            File logs = AptoideUtils.SystemU.readLogs(cachePath, LOGS_FILE_NAME,
                cardId != null ? cardId : aptoideNavigationTracker.getPrettyScreenHistory());

            if (logs != null) {
              uris.add(getUriFromFile(logs));
            }

            emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
          }
          try {
            //holy moly
            getActivity().getSupportFragmentManager()
                .beginTransaction()
                .remove(this)
                .commit();
            startActivity(emailIntent);
            getActivity().onBackPressed();
            //				Analytics.SendFeedback.sendFeedback();
          } catch (ActivityNotFoundException ex) {
            ShowMessage.asSnack(getView(), R.string.feedback_no_email);
          }
        }, throwable -> crashReport.log(throwable));
  } else {
    ShowMessage.asSnack(getView(), R.string.feedback_not_valid);
  }
}
 
Example 20
@Override
protected void onPostExecute(Void aVoid) {
    super.onPostExecute(aVoid);

    ControlHelper.unlockScreenOrientation(mActivity);
    if (mProgress != null)
        mProgress.dismiss();

    if (mIsCanceled)
        return;

    String text = mActivity.getString(R.string.not_enough_points);
    if (mNoPoints > 0)
        if (mUris.size() > 0)
            Toast.makeText(mActivity, text + " (" + mNoPoints + ")", Toast.LENGTH_LONG).show();
        else
            Toast.makeText(mActivity, text, Toast.LENGTH_LONG).show();

    if (mUris.size() == 0)
        return;

    Intent shareIntent = new Intent();
    String type = "application/gpx+xml";
    String action = Intent.ACTION_SEND;

    if (mUris.size() > 1)
        action = Intent.ACTION_SEND_MULTIPLE;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        ShareCompat.IntentBuilder builder = ShareCompat.IntentBuilder.from(mActivity);
        for (Uri uri : mUris)
            builder.addStream(uri);
        shareIntent = builder.setType(type).getIntent().setAction(action).setType(type).addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    } else {
        shareIntent = Intent.createChooser(shareIntent, mActivity.getString(R.string.menu_share));
        shareIntent.setType(type);
        shareIntent.setAction(action);
        shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (mUris.size() > 1)
            shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, mUris);
        else
            shareIntent.putExtra(Intent.EXTRA_STREAM, mUris.get(0));
    }

    try {
        mActivity.startActivity(shareIntent);
    } catch (ActivityNotFoundException e) {
        notFound(mActivity);
    }
}