android.support.v4.app
Class ShareCompat.IntentReader

java.lang.Object
  extended by android.support.v4.app.ShareCompat.IntentReader
Enclosing class:
ShareCompat

public static class ShareCompat.IntentReader
extends Object

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.


Method Summary
static ShareCompat.IntentReader from(android.app.Activity activity)
          Get an IntentReader for parsing and interpreting the sharing intent used to start the given activity.
 android.content.ComponentName getCallingActivity()
          Get the ComponentName of the Activity that invoked this sharing intent.
 android.graphics.drawable.Drawable getCallingActivityIcon()
          Get the icon of the calling activity as a Drawable if data about the calling activity is available.
 android.graphics.drawable.Drawable getCallingApplicationIcon()
          Get the icon of the calling application as a Drawable if data about the calling package is available.
 CharSequence getCallingApplicationLabel()
          Get the human-readable label (title) of the calling application if data about the calling package is available.
 String getCallingPackage()
          Get the name of the package that invoked this sharing intent.
 String[] getEmailBcc()
          Get an array of Strings, each an email address to BCC on this share.
 String[] getEmailCc()
          Get an array of Strings, each an email address to CC on this share.
 String[] getEmailTo()
          Get an array of Strings, each an email address to share to.
 String getHtmlText()
          Get the styled HTML text shared with the target activity.
 android.net.Uri getStream()
          Get a URI referring to a data stream shared with the target activity.
 android.net.Uri getStream(int index)
          Get the URI of a stream item shared with the target activity.
 int getStreamCount()
          Return the number of stream items shared.
 String getSubject()
          Get a subject heading for this share; useful when sharing via email.
 CharSequence getText()
          Get the literal text shared with the target activity.
 String getType()
          Get the mimetype of the data shared to this activity.
 boolean isMultipleShare()
          Returns true if the activity this reader was obtained for was started with an Intent.ACTION_SEND_MULTIPLE intent.
 boolean isShareIntent()
          Returns true if the activity this reader was obtained for was started with an Intent.ACTION_SEND or Intent.ACTION_SEND_MULTIPLE sharing Intent.
 boolean isSingleShare()
          Returns true if the activity this reader was obtained for was started with an Intent.ACTION_SEND intent and contains a single shared item.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

from

public static ShareCompat.IntentReader from(android.app.Activity activity)
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

isShareIntent

public boolean isShareIntent()
Returns true if the activity this reader was obtained for was started with an Intent.ACTION_SEND or Intent.ACTION_SEND_MULTIPLE sharing Intent.

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

isSingleShare

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

Returns:
true if the activity was started with an ACTION_SEND intent

isMultipleShare

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

Returns:
true if the activity was started with an ACTION_SEND_MULTIPLE intent

getType

public String getType()
Get the mimetype of the data shared to this activity.

Returns:
mimetype of the shared data
See Also:
Intent.getType()

getText

public CharSequence getText()
Get the literal text shared with the target activity.

Returns:
Literal shared text or null if none was supplied
See Also:
Intent.EXTRA_TEXT

getHtmlText

public String getHtmlText()
Get the styled HTML text shared with the target activity. If no HTML text was supplied but Intent.EXTRA_TEXT contained styled text, it will be converted to HTML if possible and returned. If the text provided by Intent.EXTRA_TEXT was not styled text, it will be escaped by Html.escapeHtml(CharSequence) and returned. If no text was provided at all, this method will return null.

Returns:
Styled text provided by the sender as HTML.

getStream

public android.net.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 isMultipleShare() returns true the application should use getStream(int) and 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:
Intent.EXTRA_STREAM

getStream

public android.net.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:
Intent.EXTRA_STREAM, Intent.ACTION_SEND_MULTIPLE

getStreamCount

public int getStreamCount()
Return the number of stream items shared. The return value will be 0 or 1 if this was an Intent.ACTION_SEND intent, or 0 or more if it was an Intent.ACTION_SEND_MULTIPLE intent.

Returns:
Count of text items contained within the Intent

getEmailTo

public 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:
Intent.EXTRA_EMAIL

getEmailCc

public 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:
Intent.EXTRA_CC

getEmailBcc

public 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:
Intent.EXTRA_BCC

getSubject

public 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:
Intent.EXTRA_SUBJECT

getCallingPackage

public 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:
Activity.getCallingPackage(), ShareCompat.EXTRA_CALLING_PACKAGE

getCallingActivity

public android.content.ComponentName getCallingActivity()
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.

Returns:
ComponentName of the calling Activity or null if unknown
See Also:
Activity.getCallingActivity(), ShareCompat.EXTRA_CALLING_ACTIVITY

getCallingActivityIcon

public android.graphics.drawable.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

getCallingApplicationIcon

public android.graphics.drawable.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

getCallingApplicationLabel

public 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


Copyright © 2013 Marek Kedzierski. All Rights Reserved.