public class

ShareCompat.IntentReader

extends java.lang.Object

 java.lang.Object

↳androidx.core.app.ShareCompat.IntentReader

Overview

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 intents ("android.intent.action.SEND") and optionally accept ("android.intent.action.SEND_MULTIPLE") if the activity is equipped to handle multiple data streams.

Summary

Constructors
publicIntentReader(Activity activity)

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

publicIntentReader(Context context, Intent intent)

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

Methods
public static ShareCompat.IntentReaderfrom(Activity activity)

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

public ComponentNamegetCallingActivity()

Get the of the Activity that invoked this sharing intent.

public DrawablegetCallingActivityIcon()

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

public DrawablegetCallingApplicationIcon()

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

public java.lang.CharSequencegetCallingApplicationLabel()

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

public java.lang.StringgetCallingPackage()

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

public java.lang.StringgetEmailBcc()

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

public java.lang.StringgetEmailCc()

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

public java.lang.StringgetEmailTo()

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

public java.lang.StringgetHtmlText()

Get the styled HTML text shared with the target activity.

public UrigetStream()

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

public UrigetStream(int index)

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

public intgetStreamCount()

Return the number of stream items shared.

public java.lang.StringgetSubject()

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

public java.lang.CharSequencegetText()

Get the literal text shared with the target activity.

public java.lang.StringgetType()

Get the mimetype of the data shared to this activity.

public booleanisMultipleShare()

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

public booleanisShareIntent()

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

public booleanisSingleShare()

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

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public IntentReader(Activity activity)

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

Parameters:

activity: Activity that was started to share content

public IntentReader(Context context, Intent intent)

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

Parameters:

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

Methods

public static ShareCompat.IntentReader from(Activity activity)

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 that was started to share content

Returns:

IntentReader for parsing sharing data

public boolean isShareIntent()

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

Returns:

true if the activity was started with an ACTION_SEND or ACTION_SEND_MULTIPLE Intent

public boolean isSingleShare()

Returns true if the activity this reader was obtained for was started with an intent and contains a single shared item. The shared content should be obtained using either the ShareCompat.IntentReader.getText() or ShareCompat.IntentReader.getStream() methods depending on the type of content shared.

Returns:

true if the activity was started with an ACTION_SEND intent

public boolean isMultipleShare()

Returns true if the activity this reader was obtained for was started with an intent. The Intent may contain more than one stream item.

Returns:

true if the activity was started with an ACTION_SEND_MULTIPLE intent

public java.lang.String getType()

Get the mimetype of the data shared to this activity.

Returns:

mimetype of the shared data

See also:

public java.lang.CharSequence getText()

Get the literal text shared with the target activity.

Returns:

Literal shared text or null if none was supplied

See also:

public java.lang.String getHtmlText()

Get the styled HTML text shared with the target activity. If no HTML text was supplied but contained styled text, it will be converted to HTML if possible and returned. If the text provided by was not styled text, it will be escaped by android.text.Html and returned. If no text was provided at all, this method will return null.

Returns:

Styled text provided by the sender as HTML.

public Uri getStream()

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

This call will fail if the share intent contains multiple stream items. If ShareCompat.IntentReader.isMultipleShare() returns true the application should use ShareCompat.IntentReader.getStream(int) and ShareCompat.IntentReader.getStreamCount() to retrieve the included stream items.

Returns:

A URI referring to a data stream to be shared or null if one was not supplied

See also:

public Uri getStream(int index)

Get the URI of a stream item shared with the target activity. Index should be in the range [0-getStreamCount()).

Parameters:

index: Index of text item to retrieve

Returns:

Requested stream item URI

See also:

public int getStreamCount()

Return the number of stream items shared. The return value will be 0 or 1 if this was an intent, or 0 or more if it was an intent.

Returns:

Count of text items contained within the Intent

public java.lang.String getEmailTo()

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

Returns:

An array of email addresses or null if none were supplied.

See also:

public java.lang.String getEmailCc()

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

Returns:

An array of email addresses or null if none were supplied.

See also:

public java.lang.String getEmailBcc()

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

Returns:

An array of email addresses or null if none were supplied.

See also:

public java.lang.String getSubject()

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

Returns:

The subject heading for this share or null if one was not supplied.

See also:

public java.lang.String getCallingPackage()

Get the name of the package that invoked this sharing intent. If the 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.

Returns:

Name of the package that started this activity or null if unknown

See also: , ShareCompat.EXTRA_CALLING_PACKAGE, ShareCompat.EXTRA_CALLING_PACKAGE_INTEROP

public ComponentName getCallingActivity()

Get the 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.

Returns:

ComponentName of the calling Activity or null if unknown

See also: , ShareCompat.EXTRA_CALLING_ACTIVITY, ShareCompat.EXTRA_CALLING_ACTIVITY_INTEROP

public Drawable getCallingActivityIcon()

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

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.

Returns:

The calling Activity's icon or null if unknown

public Drawable getCallingApplicationIcon()

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

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.

Returns:

The calling application's icon or null if unknown

public java.lang.CharSequence getCallingApplicationLabel()

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

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.

Returns:

The calling application's label or null if unknown