ShareCompat.IntentBuilder

Added in 1.1.0

public class ShareCompat.IntentBuilder


IntentBuilder is a helper for constructing ACTION_SEND and ACTION_SEND_MULTIPLE sharing intents and starting activities to share content. The ComponentName and package name of the calling activity will be included.

Summary

Public constructors

IntentBuilder(@NonNull Context launchingContext)

Create a new IntentBuilder for launching a sharing action from launchingContext.

Public methods

@NonNull ShareCompat.IntentBuilder

Add an email address to be used in the "bcc" field of the final Intent.

@NonNull ShareCompat.IntentBuilder
addEmailBcc(@NonNull String[] addresses)

Add an array of email addresses to be used in the "bcc" field of the final Intent.

@NonNull ShareCompat.IntentBuilder

Add an email address to be used in the "cc" field of the final Intent.

@NonNull ShareCompat.IntentBuilder
addEmailCc(@NonNull String[] addresses)

Add an array of email addresses to be used in the "cc" field of the final Intent.

@NonNull ShareCompat.IntentBuilder

Add an email address to be used in the "to" field of the final Intent.

@NonNull ShareCompat.IntentBuilder
addEmailTo(@NonNull String[] addresses)

Add an array of email addresses to be used in the "to" field of the final Intent.

@NonNull ShareCompat.IntentBuilder
addStream(@NonNull Uri streamUri)

Add a stream URI to the data that should be shared.

@NonNull Intent

Create an Intent that will launch the standard Android activity chooser, allowing the user to pick what activity/app on the system should handle the share.

static @NonNull ShareCompat.IntentBuilder
from(@NonNull Activity launchingActivity)

This method is deprecated.

Use the constructor of IntentBuilder

@NonNull Intent

Retrieve the Intent as configured so far by the IntentBuilder.

@NonNull ShareCompat.IntentBuilder

Set the title that will be used for the activity chooser for this share.

@NonNull ShareCompat.IntentBuilder

Set the title that will be used for the activity chooser for this share.

@NonNull ShareCompat.IntentBuilder
setEmailBcc(@Nullable String[] addresses)

Set an array of email addresses to BCC on this share.

@NonNull ShareCompat.IntentBuilder
setEmailCc(@Nullable String[] addresses)

Set an array of email addresses to CC on this share.

@NonNull ShareCompat.IntentBuilder
setEmailTo(@Nullable String[] addresses)

Set an array of email addresses as recipients of this share.

@NonNull ShareCompat.IntentBuilder

Set an HTML string to be sent as part of the share.

@NonNull ShareCompat.IntentBuilder
setStream(@Nullable Uri streamUri)

Set a stream URI to the data that should be shared.

@NonNull ShareCompat.IntentBuilder

Set a subject heading for this share; useful for sharing via email.

@NonNull ShareCompat.IntentBuilder

Set the literal text data to be sent as part of the share.

@NonNull ShareCompat.IntentBuilder
setType(@Nullable String mimeType)

Set the type of data being shared

void

Start a chooser activity for the current share intent.

Public constructors

IntentBuilder

Added in 1.5.0
public IntentBuilder(@NonNull Context launchingContext)

Create a new IntentBuilder for launching a sharing action from launchingContext.

Note that builders that are not constructed with an Activity context (or a wrapped activity context) will not set the calling activity on the returned intent.

Parameters
@NonNull Context launchingContext

Context that the share will be launched from

Public methods

addEmailBcc

Added in 1.1.0
public @NonNull ShareCompat.IntentBuilder addEmailBcc(@NonNull String address)

Add an email address to be used in the "bcc" field of the final Intent.

Parameters
@NonNull String address

Email address to BCC

Returns
@NonNull ShareCompat.IntentBuilder

This IntentBuilder for method chaining

See also
EXTRA_BCC

addEmailBcc

Added in 1.1.0
public @NonNull ShareCompat.IntentBuilder addEmailBcc(@NonNull String[] addresses)

Add an array of email addresses to be used in the "bcc" field of the final Intent.

Parameters
@NonNull String[] addresses

Email addresses to BCC

Returns
@NonNull ShareCompat.IntentBuilder

This IntentBuilder for method chaining

See also
EXTRA_BCC

addEmailCc

Added in 1.1.0
public @NonNull ShareCompat.IntentBuilder addEmailCc(@NonNull String address)

Add an email address to be used in the "cc" field of the final Intent.

Parameters
@NonNull String address

Email address to CC

Returns
@NonNull ShareCompat.IntentBuilder

This IntentBuilder for method chaining

See also
EXTRA_CC

addEmailCc

Added in 1.1.0
public @NonNull ShareCompat.IntentBuilder addEmailCc(@NonNull String[] addresses)

Add an array of email addresses to be used in the "cc" field of the final Intent.

Parameters
@NonNull String[] addresses

Email addresses to CC

Returns
@NonNull ShareCompat.IntentBuilder

This IntentBuilder for method chaining

See also
EXTRA_CC

addEmailTo

Added in 1.1.0
public @NonNull ShareCompat.IntentBuilder addEmailTo(@NonNull String address)

Add an email address to be used in the "to" field of the final Intent.

Parameters
@NonNull String address

Email address to send to

Returns
@NonNull ShareCompat.IntentBuilder

This IntentBuilder for method chaining

See also
EXTRA_EMAIL

addEmailTo

Added in 1.1.0
public @NonNull ShareCompat.IntentBuilder addEmailTo(@NonNull String[] addresses)

Add an array of email addresses to be used in the "to" field of the final Intent.

Parameters
@NonNull String[] addresses

Email addresses to send to

Returns
@NonNull ShareCompat.IntentBuilder

This IntentBuilder for method chaining

See also
EXTRA_EMAIL

addStream

Added in 1.1.0
public @NonNull ShareCompat.IntentBuilder addStream(@NonNull Uri streamUri)

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.

Parameters
@NonNull Uri streamUri

URI of the stream to share

Returns
@NonNull ShareCompat.IntentBuilder

This IntentBuilder for method chaining

createChooserIntent

Added in 1.1.0
public @NonNull Intent createChooserIntent()

Create an Intent that will launch the standard Android activity chooser, allowing the user to pick what activity/app on the system should handle the share.

Returns
@NonNull Intent

A chooser Intent for the currently configured sharing action

from

Added in 1.1.0
Deprecated in 1.5.0
public static @NonNull ShareCompat.IntentBuilder from(@NonNull Activity launchingActivity)

Create a new IntentBuilder for launching a sharing action from launchingActivity.

Parameters
@NonNull Activity launchingActivity

Activity that the share will be launched from

Returns
@NonNull ShareCompat.IntentBuilder

a new IntentBuilder instance

getIntent

Added in 1.1.0
public @NonNull Intent getIntent()

Retrieve the Intent as configured so far by the IntentBuilder. This Intent is suitable for use in a ShareActionProvider or chooser dialog.

To create an intent that will launch the activity chooser so that the user may select a target for the share, see createChooserIntent.

Returns
@NonNull Intent

The current Intent being configured by this builder

setChooserTitle

Added in 1.1.0
public @NonNull ShareCompat.IntentBuilder setChooserTitle(@StringRes int resId)

Set the title that will be used for the activity chooser for this share.

Parameters
@StringRes int resId

Resource ID of the title string to use

Returns
@NonNull ShareCompat.IntentBuilder

This IntentBuilder for method chaining

setChooserTitle

Added in 1.1.0
public @NonNull ShareCompat.IntentBuilder setChooserTitle(@Nullable CharSequence title)

Set the title that will be used for the activity chooser for this share.

Parameters
@Nullable CharSequence title

Title string

Returns
@NonNull ShareCompat.IntentBuilder

This IntentBuilder for method chaining

setEmailBcc

Added in 1.1.0
public @NonNull ShareCompat.IntentBuilder setEmailBcc(@Nullable String[] addresses)

Set an array of email addresses to BCC on this share. This replaces all current "BCC" recipients that have been set so far.

Parameters
@Nullable String[] addresses

Email addresses to BCC on the share

Returns
@NonNull ShareCompat.IntentBuilder

This IntentBuilder for method chaining

See also
EXTRA_BCC

setEmailCc

Added in 1.1.0
public @NonNull ShareCompat.IntentBuilder setEmailCc(@Nullable String[] addresses)

Set an array of email addresses to CC on this share. This replaces all current "CC" recipients that have been set so far.

Parameters
@Nullable String[] addresses

Email addresses to CC on the share

Returns
@NonNull ShareCompat.IntentBuilder

This IntentBuilder for method chaining

See also
EXTRA_CC

setEmailTo

Added in 1.1.0
public @NonNull ShareCompat.IntentBuilder setEmailTo(@Nullable String[] addresses)

Set an array of email addresses as recipients of this share. This replaces all current "to" recipients that have been set so far.

Parameters
@Nullable String[] addresses

Email addresses to send to

Returns
@NonNull ShareCompat.IntentBuilder

This IntentBuilder for method chaining

See also
EXTRA_EMAIL

setHtmlText

Added in 1.1.0
public @NonNull ShareCompat.IntentBuilder setHtmlText(@Nullable String htmlText)

Set an HTML string to be sent as part of the share. If EXTRA_TEXT has not already been supplied, a styled version of the supplied HTML text will be added as EXTRA_TEXT as parsed by Html.fromHtml.

Parameters
@Nullable String htmlText

A string containing HTML markup as a richer version of the text provided by EXTRA_TEXT.

Returns
@NonNull ShareCompat.IntentBuilder

This IntentBuilder for method chaining

See also
setText

setStream

Added in 1.1.0
public @NonNull ShareCompat.IntentBuilder setStream(@Nullable Uri streamUri)

Set a stream URI to the data that should be shared.

This replaces all currently set stream URIs and will produce a single-stream ACTION_SEND intent.

Parameters
@Nullable Uri streamUri

URI of the stream to share

Returns
@NonNull ShareCompat.IntentBuilder

This IntentBuilder for method chaining

See also
EXTRA_STREAM

setSubject

Added in 1.1.0
public @NonNull ShareCompat.IntentBuilder setSubject(@Nullable String subject)

Set a subject heading for this share; useful for sharing via email.

Parameters
@Nullable String subject

Subject heading for this share

Returns
@NonNull ShareCompat.IntentBuilder

This IntentBuilder for method chaining

See also
EXTRA_SUBJECT

setText

Added in 1.1.0
public @NonNull ShareCompat.IntentBuilder setText(@Nullable CharSequence text)

Set the literal text data to be sent as part of the share. This may be a styled CharSequence.

Parameters
@Nullable CharSequence text

Text to share

Returns
@NonNull ShareCompat.IntentBuilder

This IntentBuilder for method chaining

See also
EXTRA_TEXT

setType

Added in 1.1.0
public @NonNull ShareCompat.IntentBuilder setType(@Nullable String mimeType)

Set the type of data being shared

Parameters
@Nullable String mimeType

mimetype of the shared data

Returns
@NonNull ShareCompat.IntentBuilder

This IntentBuilder for method chaining

See also
setType

startChooser

Added in 1.1.0
public void startChooser()

Start a chooser activity for the current share intent.