/** * Add a stream URI to the data that should be shared. If this is not the first * stream URI added the final intent constructed will become an ACTION_SEND_MULTIPLE * intent. Not all apps will handle both ACTION_SEND and ACTION_SEND_MULTIPLE. * * @param streamUri URI of the stream to share * @return This IntentBuilder for method chaining * @see Intent#EXTRA_STREAM * @see Intent#ACTION_SEND * @see Intent#ACTION_SEND_MULTIPLE */ public IntentBuilder addStream(Uri streamUri) { Uri currentStream = mIntent.getParcelableExtra(Intent.EXTRA_STREAM); if (currentStream == null) { return setStream(streamUri); } if (mStreams == null) { mStreams = new ArrayList<Uri>(); } if (currentStream != null) { mIntent.removeExtra(Intent.EXTRA_STREAM); mStreams.add(currentStream); } mStreams.add(streamUri); return this; }
/** * Add a stream URI to the data that should be shared. If this is not the first * stream URI added the final intent constructed will become an ACTION_SEND_MULTIPLE * intent. Not all apps will handle both ACTION_SEND and ACTION_SEND_MULTIPLE. * * @param streamUri URI of the stream to share * @return This IntentBuilder for method chaining * @see Intent#EXTRA_STREAM * @see Intent#ACTION_SEND * @see Intent#ACTION_SEND_MULTIPLE */ public IntentBuilder addStream(Uri streamUri) { Uri currentStream = mIntent.getParcelableExtra(Intent.EXTRA_STREAM); if (currentStream == null) { return setStream(streamUri); } if (mStreams == null) { mStreams = new ArrayList<Uri>(); } if (currentStream != null) { mIntent.removeExtra(Intent.EXTRA_STREAM); mStreams.add(currentStream); } mStreams.add(streamUri); return this; }
public static void sendMail(Activity activity, ReportMail reportMail, Uri fileUri) { Intent intent = ShareCompat.IntentBuilder.from(activity) .addEmailTo(reportMail.getEmail()) .setSubject(reportMail.getSubject()) .setText(reportMail.getBody()) .setType("text/plain") .setStream(fileUri) .getIntent() .addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); activity.startActivity(intent); }
/** * Creates an intent to prompt the user for sharing text. * * @param title The name of the text being stored. * @param url The url to be shared. * @param activity The current activity. */ public static Intent shareText(String title, String url, Activity activity) { return ShareCompat.IntentBuilder.from(activity) .setSubject(title) .setText(url) .setStream(Uri.parse(url)) .setType(TEXT_PLAIN_MIME) .setChooserTitle(R.string.share) .getIntent(); }