IntentBuilder

class IntentBuilder
kotlin.Any
   ↳ androidx.core.app.ShareCompat.IntentBuilder

IntentBuilder is a helper for constructing Intent#ACTION_SEND and Intent#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 methods

open ShareCompat.IntentBuilder
addEmailBcc(@NonNull address: String)

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

open ShareCompat.IntentBuilder
addEmailBcc(@NonNull addresses: Array<String!>)

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

open ShareCompat.IntentBuilder
addEmailCc(@NonNull address: String)

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

open ShareCompat.IntentBuilder
addEmailCc(@NonNull addresses: Array<String!>)

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

open ShareCompat.IntentBuilder
addEmailTo(@NonNull address: String)

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

open ShareCompat.IntentBuilder
addEmailTo(@NonNull addresses: Array<String!>)

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

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

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

open 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.

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

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

open Intent

Retrieve the Intent as configured so far by the IntentBuilder.

open ShareCompat.IntentBuilder
setChooserTitle(@Nullable title: CharSequence?)

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

open ShareCompat.IntentBuilder
setChooserTitle(@StringRes resId: Int)

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

open ShareCompat.IntentBuilder
setEmailBcc(@Nullable addresses: Array<String!>?)

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

open ShareCompat.IntentBuilder
setEmailCc(@Nullable addresses: Array<String!>?)

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

open ShareCompat.IntentBuilder
setEmailTo(@Nullable addresses: Array<String!>?)

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

open ShareCompat.IntentBuilder
setHtmlText(@Nullable htmlText: String?)

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

open ShareCompat.IntentBuilder
setStream(@Nullable streamUri: Uri?)

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

open ShareCompat.IntentBuilder
setSubject(@Nullable subject: String?)

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

open ShareCompat.IntentBuilder
setText(@Nullable text: CharSequence?)

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

open ShareCompat.IntentBuilder
setType(@Nullable mimeType: String?)

Set the type of data being shared

open Unit

Start a chooser activity for the current share intent.

Public methods

addEmailBcc

@NonNull open fun addEmailBcc(@NonNull address: String): ShareCompat.IntentBuilder

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

Parameters
address String: Email address to BCC
Return
ShareCompat.IntentBuilder: This IntentBuilder for method chaining

See Also

addEmailBcc

@NonNull open fun addEmailBcc(@NonNull addresses: Array<String!>): ShareCompat.IntentBuilder

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

Parameters
addresses Array<String!>: Email addresses to BCC
Return
ShareCompat.IntentBuilder: This IntentBuilder for method chaining

See Also

addEmailCc

@NonNull open fun addEmailCc(@NonNull address: String): ShareCompat.IntentBuilder

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

Parameters
address String: Email address to CC
Return
ShareCompat.IntentBuilder: This IntentBuilder for method chaining

See Also

addEmailCc

@NonNull open fun addEmailCc(@NonNull addresses: Array<String!>): ShareCompat.IntentBuilder

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

Parameters
addresses Array<String!>: Email addresses to CC
Return
ShareCompat.IntentBuilder: This IntentBuilder for method chaining

See Also

addEmailTo

@NonNull open fun addEmailTo(@NonNull address: String): ShareCompat.IntentBuilder

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

Parameters
address String: Email address to send to
Return
ShareCompat.IntentBuilder: This IntentBuilder for method chaining

addEmailTo

@NonNull open fun addEmailTo(@NonNull addresses: Array<String!>): ShareCompat.IntentBuilder

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

Parameters
addresses Array<String!>: Email addresses to send to
Return
ShareCompat.IntentBuilder: This IntentBuilder for method chaining

addStream

@NonNull open fun addStream(@NonNull streamUri: Uri): ShareCompat.IntentBuilder

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
streamUri Uri: URI of the stream to share
Return
ShareCompat.IntentBuilder: This IntentBuilder for method chaining

createChooserIntent

@NonNull open fun createChooserIntent(): 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.

Return
Intent: A chooser Intent for the currently configured sharing action

from

@NonNull open static fun from(@NonNull launchingActivity: Activity): ShareCompat.IntentBuilder

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

Parameters
launchingActivity Activity: Activity that the share will be launched from
Return
ShareCompat.IntentBuilder: a new IntentBuilder instance

getIntent

@NonNull open fun getIntent(): Intent

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().

Return
Intent: The current Intent being configured by this builder

setChooserTitle

@NonNull open fun setChooserTitle(@Nullable title: CharSequence?): ShareCompat.IntentBuilder

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

Parameters
title CharSequence?: Title string
Return
ShareCompat.IntentBuilder: This IntentBuilder for method chaining

setChooserTitle

@NonNull open fun setChooserTitle(@StringRes resId: Int): ShareCompat.IntentBuilder

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

Parameters
resId Int: Resource ID of the title string to use
Return
ShareCompat.IntentBuilder: This IntentBuilder for method chaining

setEmailBcc

@NonNull open fun setEmailBcc(@Nullable addresses: Array<String!>?): ShareCompat.IntentBuilder

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

Parameters
addresses Array<String!>?: Email addresses to BCC on the share
Return
ShareCompat.IntentBuilder: This IntentBuilder for method chaining

See Also

setEmailCc

@NonNull open fun setEmailCc(@Nullable addresses: Array<String!>?): ShareCompat.IntentBuilder

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

Parameters
addresses Array<String!>?: Email addresses to CC on the share
Return
ShareCompat.IntentBuilder: This IntentBuilder for method chaining

See Also

setEmailTo

@NonNull open fun setEmailTo(@Nullable addresses: Array<String!>?): ShareCompat.IntentBuilder

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

Parameters
addresses Array<String!>?: Email addresses to send to
Return
ShareCompat.IntentBuilder: This IntentBuilder for method chaining

setHtmlText

@NonNull open fun setHtmlText(@Nullable htmlText: String?): ShareCompat.IntentBuilder

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
htmlText String?: A string containing HTML markup as a richer version of the text provided by EXTRA_TEXT.
Return
ShareCompat.IntentBuilder: This IntentBuilder for method chaining

setStream

@NonNull open fun setStream(@Nullable streamUri: Uri?): ShareCompat.IntentBuilder

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
streamUri Uri?: URI of the stream to share
Return
ShareCompat.IntentBuilder: This IntentBuilder for method chaining

setSubject

@NonNull open fun setSubject(@Nullable subject: String?): ShareCompat.IntentBuilder

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

Parameters
subject String?: Subject heading for this share
Return
ShareCompat.IntentBuilder: This IntentBuilder for method chaining

setText

@NonNull open fun setText(@Nullable text: CharSequence?): ShareCompat.IntentBuilder

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

Parameters
text CharSequence?: Text to share
Return
ShareCompat.IntentBuilder: This IntentBuilder for method chaining

setType

@NonNull open fun setType(@Nullable mimeType: String?): ShareCompat.IntentBuilder

Set the type of data being shared

Parameters
mimeType String?: mimetype of the shared data
Return
ShareCompat.IntentBuilder: This IntentBuilder for method chaining

startChooser

open fun startChooser(): Unit

Start a chooser activity for the current share intent.

Note that under most circumstances you should use ShareCompat.configureMenuItem() to add a Share item to the menu while presenting a detail view of the content to be shared instead of invoking this directly.