Android Guides | Samples

Android.Widget.ShareActionProvider Class

This is a provider for a share action.

See Also: ShareActionProvider

Syntax

[Android.Runtime.Register("android/widget/ShareActionProvider", DoNotGenerateAcw=true)]
public class ShareActionProvider : ActionProvider

Remarks

This is a provider for a share action. It is responsible for creating views that enable data sharing and also to show a sub menu with sharing activities if the hosting item is placed on the overflow menu.

java Example

 // In Activity#onCreateOptionsMenu
 public boolean onCreateOptionsMenu(Menu menu) {
     // Get the menu item.
     MenuItem menuItem = menu.findItem(R.id.my_menu_item);
     // Get the provider and hold onto it to set/change the share intent.
     mShareActionProvider = (ShareActionProvider) menuItem.getActionProvider();
     // Set history different from the default before getting the action
     // view since a call to MenuItem.getActionView() calls
     // onCreateActionView() which uses the backing file name. Omit this
     // line if using the default share history file is desired.
     mShareActionProvider.setShareHistoryFileName("custom_share_history.xml");
     . . .
 }

 // Somewhere in the application.
 public void doShare(Intent shareIntent) {
     // When you want to share set the share intent.
     mShareActionProvider.setShareIntent(shareIntent);
 }

Here is how to use the action provider with custom backing file in a IMenuItem:

Note: While the sample snippet demonstrates how to use this provider in the context of a menu item, the use of the provider is not limited to menu items.

See Also

[Android Documentation]

Requirements

Namespace: Android.Widget
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 14

The members of Android.Widget.ShareActionProvider are listed below.

See Also: ActionProvider

Public Constructors

Creates a new instance.

Protected Constructors

A constructor used when creating managed representations of JNI objects; called by the runtime.

Public Fields

const
DefaultShareHistoryFileNameString. The default name for storing share history.

Protected Properties

[read-only]
override
ThresholdClassIntPtr. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.
[read-only]
override
ThresholdTypeType. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Public Methods

override
OnCreateActionView() : View
Factory method called by the Android framework to create new action views.
SetOnShareTargetSelectedListener(ShareActionProvider+IOnShareTargetSelectedListener)
Sets a listener to be notified when a share target has been selected.
SetShareHistoryFileName(String)
Sets the file name of a file for persisting the share history which history will be used for ordering share targets.
SetShareIntent(Intent)
Sets an intent with information about the share action.

Public Events