ShareCompat

public final class ShareCompat
extends Object

java.lang.Object
   ↳ androidx.core.app.ShareCompat


Extra helper functionality for sharing data between activities. ShareCompat provides functionality to extend the Intent.ACTION_SEND/ Intent.ACTION_SEND_MULTIPLE protocol and support retrieving more info about the activity that invoked a social sharing action. ShareCompat.IntentBuilder provides helper functions for constructing a sharing intent that always includes data about the calling activity and app. This lets the called activity provide attribution for the app that shared content. Constructing an intent this way can be done in a method-chaining style. To obtain an IntentBuilder with info about your calling activity, use the static method ShareCompat.IntentBuilder.from(Activity). ShareCompat.IntentReader provides helper functions for parsing the defined extras within an Intent.ACTION_SEND or Intent.ACTION_SEND_MULTIPLE intent used to launch an activity. You can also obtain a Drawable for the caller's application icon and the application's localized label (the app's human-readable name). Social apps that enable sharing content are encouraged to use this information to call out the app that the content was shared from.

Summary

Nested classes

class ShareCompat.IntentBuilder

IntentBuilder is a helper for constructing Intent.ACTION_SEND and Intent.ACTION_SEND_MULTIPLE sharing intents and starting activities to share content. 

class ShareCompat.IntentReader

IntentReader is a helper for reading the data contained within a sharing (ACTION_SEND) Intent. 

Constants

String EXTRA_CALLING_ACTIVITY

Intent extra that stores the ComponentName of the calling activity for an ACTION_SEND intent.

String EXTRA_CALLING_ACTIVITY_INTEROP

Intent extra that stores the ComponentName of the calling activity for an ACTION_SEND intent.

String EXTRA_CALLING_PACKAGE

Intent extra that stores the name of the calling package for an ACTION_SEND intent.

String EXTRA_CALLING_PACKAGE_INTEROP

Intent extra that stores the name of the calling package for an ACTION_SEND intent.

Public methods

static void configureMenuItem(Menu menu, int menuItemId, ShareCompat.IntentBuilder shareIntent)

This method is deprecated. Use the system sharesheet. See https://developer.android.com/training/sharing/send

static void configureMenuItem(MenuItem item, ShareCompat.IntentBuilder shareIntent)

This method is deprecated. Use the system sharesheet. See https://developer.android.com/training/sharing/send

static ComponentName getCallingActivity(Activity calledActivity)

Retrieve the ComponentName of the activity that launched calledActivity from a share intent.

static String getCallingPackage(Activity calledActivity)

Retrieve the name of the package that launched calledActivity from a share intent.

Inherited methods

Constants

EXTRA_CALLING_ACTIVITY

public static final String EXTRA_CALLING_ACTIVITY

Intent extra that stores the ComponentName of the calling activity for an ACTION_SEND intent. Instead of using this constant directly, consider using getCallingPackage(Activity) or ShareCompat.IntentReader.getCallingPackage().

Constant Value: "androidx.core.app.EXTRA_CALLING_ACTIVITY"

EXTRA_CALLING_ACTIVITY_INTEROP

public static final String EXTRA_CALLING_ACTIVITY_INTEROP

Intent extra that stores the ComponentName of the calling activity for an ACTION_SEND intent. Note that this is only for interoperability between pre-1.0 AndroidX and AndroidX 1.1+ worlds. You are strongly encouraged to use getCallingPackage(Activity) or ShareCompat.IntentReader.getCallingPackage().

Constant Value: "android.support.v4.app.EXTRA_CALLING_ACTIVITY"

EXTRA_CALLING_PACKAGE

public static final String EXTRA_CALLING_PACKAGE

Intent extra that stores the name of the calling package for an ACTION_SEND intent. When an activity is started using startActivityForResult this is redundant info. (It is also provided by Activity.getCallingPackage().) Instead of using this constant directly, consider using getCallingPackage(Activity) or ShareCompat.IntentReader.getCallingPackage().

Constant Value: "androidx.core.app.EXTRA_CALLING_PACKAGE"

EXTRA_CALLING_PACKAGE_INTEROP

public static final String EXTRA_CALLING_PACKAGE_INTEROP

Intent extra that stores the name of the calling package for an ACTION_SEND intent. When an activity is started using startActivityForResult this is redundant info. (It is also provided by Activity.getCallingPackage().) Note that this is only for interoperability between pre-1.0 AndroidX and AndroidX 1.1+ worlds. You are strongly encouraged to use getCallingPackage(Activity) or ShareCompat.IntentReader.getCallingPackage().

Constant Value: "android.support.v4.app.EXTRA_CALLING_PACKAGE"

Public methods

configureMenuItem

public static void configureMenuItem (Menu menu, 
                int menuItemId, 
                ShareCompat.IntentBuilder shareIntent)

This method is deprecated.
Use the system sharesheet. See https://developer.android.com/training/sharing/send

Configure a menu item to act as a sharing action.

Parameters
menu Menu: Menu containing the item to use for sharing

menuItemId int: ID of the share item within menu

shareIntent ShareCompat.IntentBuilder: IntentBuilder with data about the content to share

configureMenuItem

public static void configureMenuItem (MenuItem item, 
                ShareCompat.IntentBuilder shareIntent)

This method is deprecated.
Use the system sharesheet. See https://developer.android.com/training/sharing/send

Configure a MenuItem to act as a sharing action.

This method will configure a ShareActionProvider to provide a more robust UI for selecting the target of the share. History will be tracked for each calling activity in a file named with the prefix ".sharecompat_" in the application's private data directory. If the application wishes to set this MenuItem to show as an action in the Action Bar it should use M