# ShareCompat

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  
belongs to Maven artifact com.android.support:support-compat:28.0.0-alpha1  
Summary:[Nested Classes](https://developer.android.com/reference/android/support/v4/app/ShareCompat#nestedclasses)\|[Constants](https://developer.android.com/reference/android/support/v4/app/ShareCompat#constants)\|[Methods](https://developer.android.com/reference/android/support/v4/app/ShareCompat#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/support/v4/app/ShareCompat#inhmethods)\|[\[Expand All\]](https://developer.android.com/reference/android/support/v4/app/ShareCompat#)  

# ShareCompat

| This package is part of the Android[support library](https://developer.android.com/topic/libraries/support-library)which is no longer maintained. The support library has been superseded by[AndroidX](https://developer.android.com/jetpack/androidx)which is part of[Jetpack](https://developer.android.com/jetpack). We recommend using the AndroidX libraries in all new projects. You should also consider[migrating](https://developer.android.com/jetpack/androidx/migrate)existing projects to AndroidX. To find the AndroidX class that maps to this deprecated class, see the AndroidX support library[class mappings](https://developer.android.com/jetpack/androidx/migrate/class-mappings).

`
public

final

class
ShareCompat
`  
`

extends Object


``


`

|---|------------------------------------|
| java.lang.Object                      ||
| ↳ | android.support.v4.app.ShareCompat |

<br />

*** ** * ** ***

Extra helper functionality for sharing data between activities. ShareCompat provides functionality to extend the[ACTION_SEND](https://developer.android.com/reference/android/content/Intent.html#ACTION_SEND)/[ACTION_SEND_MULTIPLE](https://developer.android.com/reference/android/content/Intent.html#ACTION_SEND_MULTIPLE)protocol and support retrieving more info about the activity that invoked a social sharing action.[ShareCompat.IntentBuilder](https://developer.android.com/reference/android/support/v4/app/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[from(Activity)](https://developer.android.com/reference/android/support/v4/app/ShareCompat.IntentBuilder#from(android.app.Activity)).[ShareCompat.IntentReader](https://developer.android.com/reference/android/support/v4/app/ShareCompat.IntentReader)provides helper functions for parsing the defined extras within an[ACTION_SEND](https://developer.android.com/reference/android/content/Intent.html#ACTION_SEND)or[ACTION_SEND_MULTIPLE](https://developer.android.com/reference/android/content/Intent.html#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](https://developer.android.com/reference/android/support/v4/app/ShareCompat.IntentBuilder) IntentBuilder is a helper for constructing[ACTION_SEND](https://developer.android.com/reference/android/content/Intent.html#ACTION_SEND)and[ACTION_SEND_MULTIPLE](https://developer.android.com/reference/android/content/Intent.html#ACTION_SEND_MULTIPLE)sharing intents and starting activities to share content. |
| ` class` | [ShareCompat.IntentReader](https://developer.android.com/reference/android/support/v4/app/ShareCompat.IntentReader) IntentReader is a helper for reading the data contained within a sharing (ACTION_SEND) Intent.                                                                                                                                                                                                                         |

|                                                                                                                                                  ### Constants                                                                                                                                                  ||
|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `String` | [EXTRA_CALLING_ACTIVITY](https://developer.android.com/reference/android/support/v4/app/ShareCompat#EXTRA_CALLING_ACTIVITY) Intent extra that stores the[ComponentName](https://developer.android.com/reference/android/content/ComponentName.html)of the calling activity for an ACTION_SEND intent. |
| `String` | [EXTRA_CALLING_PACKAGE](https://developer.android.com/reference/android/support/v4/app/ShareCompat#EXTRA_CALLING_PACKAGE) Intent extra that stores the name of the calling package for an ACTION_SEND intent.                                                                                         |

|                                                                                                                                                                                                                                                                                                                    ### Public methods                                                                                                                                                                                                                                                                                                                    ||
|-------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` static void`                                                                                        | ` `[configureMenuItem](https://developer.android.com/reference/android/support/v4/app/ShareCompat#configureMenuItem(android.view.MenuItem, android.support.v4.app.ShareCompat.IntentBuilder))`(`[MenuItem](https://developer.android.com/reference/android/view/MenuItem.html)` item, `[ShareCompat.IntentBuilder](https://developer.android.com/reference/android/support/v4/app/ShareCompat.IntentBuilder)` shareIntent) ` Configure a[MenuItem](https://developer.android.com/reference/android/view/MenuItem.html)to act as a sharing action. |
| ` static void`                                                                                        | ` `[configureMenuItem](https://developer.android.com/reference/android/support/v4/app/ShareCompat#configureMenuItem(android.view.Menu, int, android.support.v4.app.ShareCompat.IntentBuilder))`(`[Menu](https://developer.android.com/reference/android/view/Menu.html)` menu, int menuItemId, `[ShareCompat.IntentBuilder](https://developer.android.com/reference/android/support/v4/app/ShareCompat.IntentBuilder)` shareIntent) ` Configure a menu item to act as a sharing action.                                                           |
| ` static `[ComponentName](https://developer.android.com/reference/android/content/ComponentName.html) | ` `[getCallingActivity](https://developer.android.com/reference/android/support/v4/app/ShareCompat#getCallingActivity(android.app.Activity))`(`[Activity](https://developer.android.com/reference/android/app/Activity.html)` calledActivity) ` Retrieve the ComponentName of the activity that launched calledActivity from a share intent.                                                                                                                                                                                                      |
| ` static String`                                                                                      | ` `[getCallingPackage](https://developer.android.com/reference/android/support/v4/app/ShareCompat#getCallingPackage(android.app.Activity))`(`[Activity](https://developer.android.com/reference/android/app/Activity.html)` calledActivity) ` Retrieve the name of the package that launched calledActivity from a share intent.                                                                                                                                                                                                                  |

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/v4/app/ShareCompat#)From class` java.lang.Object ` |-------------------|-------------------------------| | ` Object`         | ` clone() `                   | | ` boolean`        | ` equals(Object arg0) `       | | ` void`           | ` finalize() `                | | ` final Class<?>` | ` getClass() `                | | ` int`            | ` hashCode() `                | | ` final void`     | ` notify() `                  | | ` final void`     | ` notifyAll() `               | | ` String`         | ` toString() `                | | ` final void`     | ` wait(long arg0, int arg1) ` | | ` final void`     | ` wait(long arg0) `           | | ` final void`     | ` wait() `                    | ||

## Constants

### EXTRA_CALLING_ACTIVITY

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
String EXTRA_CALLING_ACTIVITY
```

Intent extra that stores the[ComponentName](https://developer.android.com/reference/android/content/ComponentName.html)of the calling activity for an ACTION_SEND intent.

<br />

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

### EXTRA_CALLING_PACKAGE

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
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[getCallingPackage()](https://developer.android.com/reference/android/app/Activity.html#getCallingPackage()).) Instead of using this constant directly, consider using[getCallingPackage(Activity)](https://developer.android.com/reference/android/support/v4/app/ShareCompat#getCallingPackage(android.app.Activity))or[getCallingPackage()](https://developer.android.com/reference/android/support/v4/app/ShareCompat.IntentReader#getCallingPackage()).

<br />

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

## Public methods

### configureMenuItem

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

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

Configure a[MenuItem](https://developer.android.com/reference/android/view/MenuItem.html)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[setShowAsAction(int)](https://developer.android.com/reference/android/view/MenuItem.html#setShowAsAction(int))to request that behavior in addition to calling this method.

During the calling activity's lifecycle, if data within the share intent must change the app should change that state in one of several ways:

- Call[invalidateOptionsMenu(Activity)](https://developer.android.com/reference/android/support/v4/app/ActivityCompat#invalidateOptionsMenu(android.app.Activity)). If the app uses the Action Bar its menu will be recreated and rebuilt. If not, the activity will receive a call to[onPrepareOptionsMenu(Menu)](https://developer.android.com/reference/android/app/Activity.html#onPrepareOptionsMenu(android.view.Menu))the next time the user presses the menu key to open the options menu panel. The activity can then call configureMenuItem again with a new or altered IntentBuilder to reconfigure the share menu item.
- Keep a reference to the MenuItem object for the share item once it has been created and call configureMenuItem to update the associated sharing intent as needed.

<br />

<br />

|                                              Parameters                                               ||
|---------------|----------------------------------------------------------------------------------------|
| `item`        | `MenuItem`: MenuItem to configure for sharing <br />                                   |
| `shareIntent` | `ShareCompat.IntentBuilder`: IntentBuilder with data about the content to share <br /> |

### configureMenuItem

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

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

Configure a menu item to act as a sharing action.

<br />

|                                              Parameters                                               ||
|---------------|----------------------------------------------------------------------------------------|
| `menu`        | `Menu`: Menu containing the item to use for sharing <br />                             |
| `menuItemId`  | `int`: ID of the share item within menu <br />                                         |
| `shareIntent` | `ShareCompat.IntentBuilder`: IntentBuilder with data about the content to share <br /> |

**See also:**

- [configureMenuItem(MenuItem, IntentBuilder)](https://developer.android.com/reference/android/support/v4/app/ShareCompat#configureMenuItem(android.view.MenuItem, android.support.v4.app.ShareCompat.IntentBuilder))  

### getCallingActivity

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
ComponentName getCallingActivity (Activity calledActivity)
```

Retrieve the ComponentName of the activity that launched calledActivity from a share intent. Apps that provide social sharing functionality can use this to provide attribution for the app that shared the content.

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

<br />

<br />

|                                        Parameters                                        ||
|------------------|------------------------------------------------------------------------|
| `calledActivity` | `Activity`: Current activity that was launched to share content <br /> |

|                                                                  Returns                                                                  ||
|---------------------------------------------------------------------------------------------|----------------------------------------------|
| [ComponentName](https://developer.android.com/reference/android/content/ComponentName.html) | ComponentName of the calling activity <br /> |

### getCallingPackage

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
String getCallingPackage (Activity calledActivity)
```

Retrieve the name of the package that launched calledActivity from a share intent. Apps that provide social sharing functionality can use this to provide attribution for the app that shared the content.

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

<br />

<br />

|                                        Parameters                                        ||
|------------------|------------------------------------------------------------------------|
| `calledActivity` | `Activity`: Current activity that was launched to share content <br /> |

|                   Returns                    ||
|----------|------------------------------------|
| `String` | Name of the calling package <br /> |

-

  ## Annotations

  - [NotificationCompat.Action.SemanticAction](https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Action.SemanticAction)
-

  ## Interfaces

  - [ActionBarDrawerToggle.Delegate](https://developer.android.com/reference/android/support/v4/app/ActionBarDrawerToggle.Delegate)
  - [ActionBarDrawerToggle.DelegateProvider](https://developer.android.com/reference/android/support/v4/app/ActionBarDrawerToggle.DelegateProvider)
  - [ActivityCompat.OnRequestPermissionsResultCallback](https://developer.android.com/reference/android/support/v4/app/ActivityCompat.OnRequestPermissionsResultCallback)
  - [ActivityCompat.PermissionCompatDelegate](https://developer.android.com/reference/android/support/v4/app/ActivityCompat.PermissionCompatDelegate)
  - [FragmentManager.BackStackEntry](https://developer.android.com/reference/android/support/v4/app/FragmentManager.BackStackEntry)
  - [FragmentManager.OnBackStackChangedListener](https://developer.android.com/reference/android/support/v4/app/FragmentManager.OnBackStackChangedListener)
  - [LoaderManager.LoaderCallbacks](https://developer.android.com/reference/android/support/v4/app/LoaderManager.LoaderCallbacks)
  - [NotificationCompat.Action.Extender](https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Action.Extender)
  - [NotificationCompat.Extender](https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Extender)
  - [SharedElementCallback.OnSharedElementsReadyListener](https://developer.android.com/reference/android/support/v4/app/SharedElementCallback.OnSharedElementsReadyListener)
  - [TaskStackBuilder.SupportParentable](https://developer.android.com/reference/android/support/v4/app/TaskStackBuilder.SupportParentable)
-

  ## Classes

  - [ActionBarDrawerToggle](https://developer.android.com/reference/android/support/v4/app/ActionBarDrawerToggle)
  - [ActivityCompat](https://developer.android.com/reference/android/support/v4/app/ActivityCompat)
  - [ActivityManagerCompat](https://developer.android.com/reference/android/support/v4/app/ActivityManagerCompat)
  - [ActivityOptionsCompat](https://developer.android.com/reference/android/support/v4/app/ActivityOptionsCompat)
  - [AlarmManagerCompat](https://developer.android.com/reference/android/support/v4/app/AlarmManagerCompat)
  - [AppLaunchChecker](https://developer.android.com/reference/android/support/v4/app/AppLaunchChecker)
  - [AppOpsManagerCompat](https://developer.android.com/reference/android/support/v4/app/AppOpsManagerCompat)
  - [BundleCompat](https://developer.android.com/reference/android/support/v4/app/BundleCompat)
  - [DialogFragment](https://developer.android.com/reference/android/support/v4/app/DialogFragment)
  - [Fragment](https://developer.android.com/reference/android/support/v4/app/Fragment)
  - [Fragment.SavedState](https://developer.android.com/reference/android/support/v4/app/Fragment.SavedState)
  - [FragmentActivity](https://developer.android.com/reference/android/support/v4/app/FragmentActivity)
  - [FragmentContainer](https://developer.android.com/reference/android/support/v4/app/FragmentContainer)
  - [FragmentController](https://developer.android.com/reference/android/support/v4/app/FragmentController)
  - [FragmentHostCallback](https://developer.android.com/reference/android/support/v4/app/FragmentHostCallback)
  - [FragmentManager](https://developer.android.com/reference/android/support/v4/app/FragmentManager)
  - [FragmentManager.FragmentLifecycleCallbacks](https://developer.android.com/reference/android/support/v4/app/FragmentManager.FragmentLifecycleCallbacks)
  - [FragmentManagerNonConfig](https://developer.android.com/reference/android/support/v4/app/FragmentManagerNonConfig)
  - [FragmentPagerAdapter](https://developer.android.com/reference/android/support/v4/app/FragmentPagerAdapter)
  - [FragmentStatePagerAdapter](https://developer.android.com/reference/android/support/v4/app/FragmentStatePagerAdapter)
  - [FragmentTabHost](https://developer.android.com/reference/android/support/v4/app/FragmentTabHost)
  - [FragmentTransaction](https://developer.android.com/reference/android/support/v4/app/FragmentTransaction)
  - [FrameMetricsAggregator](https://developer.android.com/reference/android/support/v4/app/FrameMetricsAggregator)
  - [JobIntentService](https://developer.android.com/reference/android/support/v4/app/JobIntentService)
  - [ListFragment](https://developer.android.com/reference/android/support/v4/app/ListFragment)
  - [LoaderManager](https://developer.android.com/reference/android/support/v4/app/LoaderManager)
  - [NavUtils](https://developer.android.com/reference/android/support/v4/app/NavUtils)
  - [NotificationCompat](https://developer.android.com/reference/android/support/v4/app/NotificationCompat)
  - [NotificationCompat.Action](https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Action)
  - [NotificationCompat.Action.Builder](https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Action.Builder)
  - [NotificationCompat.Action.WearableExtender](https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Action.WearableExtender)
  - [NotificationCompat.BigPictureStyle](https://developer.android.com/reference/android/support/v4/app/NotificationCompat.BigPictureStyle)
  - [NotificationCompat.BigTextStyle](https://developer.android.com/reference/android/support/v4/app/NotificationCompat.BigTextStyle)
  - [NotificationCompat.Builder](https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder)
  - [NotificationCompat.CarExtender](https://developer.android.com/reference/android/support/v4/app/NotificationCompat.CarExtender)
  - [NotificationCompat.CarExtender.UnreadConversation](https://developer.android.com/reference/android/support/v4/app/NotificationCompat.CarExtender.UnreadConversation)
  - [NotificationCompat.CarExtender.UnreadConversation.Builder](https://developer.android.com/reference/android/support/v4/app/NotificationCompat.CarExtender.UnreadConversation.Builder)
  - [NotificationCompat.DecoratedCustomViewStyle](https://developer.android.com/reference/android/support/v4/app/NotificationCompat.DecoratedCustomViewStyle)
  - [NotificationCompat.InboxStyle](https://developer.android.com/reference/android/support/v4/app/NotificationCompat.InboxStyle)
  - [NotificationCompat.MessagingStyle](https://developer.android.com/reference/android/support/v4/app/NotificationCompat.MessagingStyle)
  - [NotificationCompat.MessagingStyle.Message](https://developer.android.com/reference/android/support/v4/app/NotificationCompat.MessagingStyle.Message)
  - [NotificationCompat.Style](https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Style)
  - [NotificationCompat.WearableExtender](https://developer.android.com/reference/android/support/v4/app/NotificationCompat.WearableExtender)
  - [NotificationCompatExtras](https://developer.android.com/reference/android/support/v4/app/NotificationCompatExtras)
  - [NotificationCompatSideChannelService](https://developer.android.com/reference/android/support/v4/app/NotificationCompatSideChannelService)
  - [NotificationManagerCompat](https://developer.android.com/reference/android/support/v4/app/NotificationManagerCompat)
  - [RemoteInput](https://developer.android.com/reference/android/support/v4/app/RemoteInput)
  - [RemoteInput.Builder](https://developer.android.com/reference/android/support/v4/app/RemoteInput.Builder)
  - [ServiceCompat](https://developer.android.com/reference/android/support/v4/app/ServiceCompat)
  - [ShareCompat](https://developer.android.com/reference/android/support/v4/app/ShareCompat)
  - [ShareCompat.IntentBuilder](https://developer.android.com/reference/android/support/v4/app/ShareCompat.IntentBuilder)
  - [ShareCompat.IntentReader](https://developer.android.com/reference/android/support/v4/app/ShareCompat.IntentReader)
  - [SharedElementCallback](https://developer.android.com/reference/android/support/v4/app/SharedElementCallback)
  - [TaskStackBuilder](https://developer.android.com/reference/android/support/v4/app/TaskStackBuilder)
-

  ## Exceptions

  - [Fragment.InstantiationException](https://developer.android.com/reference/android/support/v4/app/Fragment.InstantiationException)