public final class ShareResult

  1. Object
  2. ShareResult

Outcome of a share request initiated through Display.share or ShareButton.

Status semantics:

  • SHARED_TO: the user picked a target and the system accepted the share. getPackageName() returns the chosen target’s identifier: the Android package name (e.g. com.whatsapp) or, on iOS, the UIActivityType (e.g. com.apple.UIKit.activity.PostToTwitter).
  • DISMISSED: the user cancelled the share sheet without picking a target.
  • FAILED: the share could not be completed. getError() may carry a short, platform-supplied description (no stack traces).

Instances are immutable. Construct through the static factories.

Fields

public static final int STATUS_SHARED_TO = 1Status of a ShareResult.
public static final int STATUS_DISMISSED = 2User dismissed/cancelled the share sheet.
public static final int STATUS_FAILED = 3Share could not be completed.

Methods

public static ShareResult sharedTo(String packageName)Build a SHARED_TO result.
public static ShareResult dismissed()Build a DISMISSED result.
public static ShareResult failed(String message)Build a FAILED result with an optional platform message.
public int getStatus()Numeric status: one of STATUS_SHARED_TO, STATUS_DISMISSED, STATUS_FAILED.
public boolean isSharedTo()True iff status == STATUS_SHARED_TO.
public boolean isDismissed()True iff status == STATUS_DISMISSED.
public boolean isFailed()True iff status == STATUS_FAILED.
public String getPackageName()Chosen target identifier when the user picked a destination, otherwise null.
public String getError()Platform-supplied message when isFailed is true, otherwise null.
public String toString()Returns a string representation of the object.

Inherited methods

Field details

STATUS_SHARED_TO

public static final int STATUS_SHARED_TO = 1
Status of a ShareResult.

STATUS_DISMISSED

public static final int STATUS_DISMISSED = 2
User dismissed/cancelled the share sheet.

STATUS_FAILED

public static final int STATUS_FAILED = 3
Share could not be completed.

Method details

sharedTo

public static ShareResult sharedTo(String packageName)

Build a SHARED_TO result.

packageName is the platform-specific identifier of the chosen target (Android package name or iOS UIActivityType). It may be null when the platform does not expose the selection (older Android versions, web share API).

dismissed

public static ShareResult dismissed()
Build a DISMISSED result.

failed

public static ShareResult failed(String message)
Build a FAILED result with an optional platform message.

getStatus

public int getStatus()

isSharedTo

public boolean isSharedTo()
True iff status == STATUS_SHARED_TO.

isDismissed

public boolean isDismissed()
True iff status == STATUS_DISMISSED.

isFailed

public boolean isFailed()
True iff status == STATUS_FAILED.

getPackageName

public String getPackageName()
Chosen target identifier when the user picked a destination, otherwise null.

getError

public String getError()
Platform-supplied message when isFailed is true, otherwise null.

toString

public String toString()
Returns a string representation of the object. In general, the toString method returns a string that “textually represents” this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@’, and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + ‘@’ + Integer.toHexString(hashCode())