Android 12 Developer Preview is here! Try it out, and give us your feedback!

IntentReader

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

IntentReader is a helper for reading the data contained within a sharing (ACTION_SEND) Intent. It provides methods to parse standard elements included with a share in addition to extra metadata about the app that shared the content.

Social sharing apps are encouraged to provide attribution for the app that shared the content. IntentReader offers access to the application label, calling activity info, and application icon of the app that shared the content. This data may have been provided voluntarily by the calling app and should always be displayed to the user before submission for manual verification. The user should be offered the option to omit this information from shared posts if desired.

Activities that intend to receive sharing intents should configure an intent-filter to accept Intent#ACTION_SEND intents ("android.intent.action.SEND") and optionally accept Intent#ACTION_SEND_MULTIPLE ("android.intent.action.SEND_MULTIPLE") if the activity is equipped to handle multiple data streams.

Summary

Public constructors
<init>(@NonNull activity: Activity)

Create an IntentReader for parsing and interpreting the sharing intent used to start the given activity.

<init>(@NonNull context: Context, @NonNull intent: Intent)

Create an IntentReader for parsing and interpreting the given sharing intent.

Public methods
open static ShareCompat.IntentReader
from(@NonNull activity: Activity)

Get an IntentReader for parsing and interpreting the sharing intent used to start the given activity.

open ComponentName?

Get the ComponentName of the Activity that invoked this sharing intent.

open Drawable?

Get the icon of the calling activity as a Drawable if data about the calling activity is available.

open Drawable?

Get the icon of the calling application as a Drawable if data about the calling package is available.

open CharSequence?

Get the human-readable label (title) of the calling application if data about the calling package is available.

open String?

Get the name of the package that invoked this sharing intent.

open Array<String!>?

Get an array of Strings, each an email address to BCC on this share.

open Array<String!>?

Get an array of Strings, each an email address to CC on this share.

open Array<String!>?

Get an array of Strings, each an email address to share to.

open String?

Get the styled HTML text shared with the target activity.

open Uri?

Get a URI referring to a data stream shared with the target activity.

open Uri?
getStream(index: Int)

Get the URI of a stream item shared with the target activity.

open Int

Return the number of stream items shared.

open String?

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

open CharSequence?

Get the literal text shared with the target activity.

open String?

Get the mimetype of the data shared to this activity.

open Boolean

Returns true if the activity this reader was obtained for was started with an Intent#ACTION_SEND_MULTIPLE intent.

open Boolean

Returns true if the activity this reader was obtained for was started with an Intent#ACTION_SEND or Intent#ACTION_SEND_MULTIPLE sharing Intent.

open Boolean

Returns true if the activity this reader was obtained for was started with an Intent#ACTION_SEND intent and contains a single shared item.

Public constructors

<init>

IntentReader(@NonNull activity: Activity)

Create an IntentReader for parsing and interpreting the sharing intent used to start the given activity.

Parameters
activity Activity: Activity that was started to share content

<init>

IntentReader(
    @NonNull context: Context,
    @NonNull intent: Intent)

Create an IntentReader for parsing and interpreting the given sharing intent.

Parameters
context Context: Context that was started to share content
intent Intent: Intent that was used to start the context

Public methods

from

@NonNull open static fun from(@NonNull activity: Activity): ShareCompat.IntentReader

Deprecated: Use the constructor of IntentReader instead

Get an IntentReader for parsing and interpreting the sharing intent used to start the given activity.

Parameters
activity Activity: Activity that was started to share content
Return
ShareCompat.IntentReader IntentReader for parsing sharing data

getCallingActivity

@Nullable open fun getCallingActivity(): ComponentName?

Get the ComponentName of the Activity that invoked this sharing intent. If the target sharing activity was not started for a result, IntentBuilder will read this from extra metadata placed in the intent by ShareBuilder.

Note: This data may have been provided voluntarily by the calling application. As such it should not be trusted for accuracy in the context of security or verification.

Return
ComponentName? ComponentName of the calling Activity or null if unknown