ChooserTarget

public final class ChooserTarget
extends Object implements Parcelable

java.lang.Object
   ↳ android.service.chooser.ChooserTarget


This class was deprecated in API level 30.
For publishing direct share targets, please follow the instructions in https://developer.android.com/training/sharing/receive.html#providing-direct-share-targets instead.

A ChooserTarget represents a deep-link into an application as returned by a ChooserTargetService.

A chooser target represents a specific deep link target into an application exposed for selection by the user. This might be a frequently emailed contact, a recently active group messaging conversation, a folder in a cloud storage app, a collection of related items published on a social media service or any other contextually relevant grouping of target app + relevant metadata.

Creators of chooser targets should consult the relevant design guidelines for the type of target they are presenting. For example, targets involving people should be presented with a circular icon.

Summary

Inherited constants

Fields

public static final Creator<ChooserTarget> CREATOR

Public constructors

ChooserTarget(CharSequence title, Icon icon, float score, ComponentName componentName, Bundle intentExtras)

Construct a deep link target for presentation by a chooser UI.

Public methods

int describeContents()

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.

ComponentName getComponentName()

Returns the ComponentName of the Activity that should be launched for this ChooserTarget.

Icon getIcon()

Returns the icon representing this target for display to a user.

Bundle getIntentExtras()

Returns the Bundle of extras to be added to an intent launched to this target.

float getScore()

Returns the ranking score supplied by the creator of this ChooserTarget.

CharSequence getTitle()

Returns the title of this target for display to a user.

String toString()

Returns a string representation of the object.

void writeToParcel(Parcel dest, int flags)

Flatten this object in to a Parcel.

Inherited methods

Fields

CREATOR

Added in API level 23
public static final Creator<ChooserTarget> CREATOR

Public constructors

ChooserTarget

Added in API level 23
public ChooserTarget (CharSequence title, 
                Icon icon, 
                float score, 
                ComponentName componentName, 
                Bundle intentExtras)

Construct a deep link target for presentation by a chooser UI.

A target is composed of a title and an icon for presentation to the user. The UI presenting this target may truncate the title if it is too long to be presented in the available space, as well as crop, resize or overlay the supplied icon.

The creator of a target may supply a ranking score. This score is assumed to be relative to the other targets supplied by the same query. Scores should be in the range from 0.0f (unlikely match) to 1.0f (very relevant match). Scores for a set of targets do not need to sum to 1.

The ComponentName must be the name of an Activity component in the creator's own package, or an exported component from any other package. You may provide an optional Bundle of extras that will be merged into the final intent before it is sent to the target Activity; use this to add any additional data about the deep link that the target activity will read. e.g. conversation IDs, email addresses, etc.

Take care not to place custom Parcelable types into the extras bundle, as the system will not be able to unparcel them to merge them.

Parameters
title CharSequence: title of this target that will be shown to a user

icon Icon: icon to represent this target

score float: ranking score for this target between 0.0f and 1.0f, inclusive

componentName ComponentName: Name of the component to be launched if this target is chosen

intentExtras Bundle: Bundle of extras to merge with the extras of the launched intent This value may be null.

Public methods

describeContents

Added in API level 23
public int describeContents ()

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. For example, if the object will include a file descriptor in the output of writeToParcel(android.os.Parcel, int), the return value of this method must include the CONTENTS_FILE_DESCRIPTOR bit.

Returns
int a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either 0 or CONTENTS_FILE_DESCRIPTOR

getComponentName

Added in API level 23
public ComponentName getComponentName ()

Returns the ComponentName of the Activity that should be launched for this ChooserTarget.

Returns
ComponentName the name of the target Activity to launch

getIcon

Added in API level 23
public Icon getIcon ()

Returns the icon representing this target for display to a user. The UI displaying the icon may crop, resize or overlay this icon.

Returns
Icon the icon representing this target, intended to be shown to a user

getIntentExtras

Added in API level 23
public Bundle getIntentExtras ()

Returns the Bundle of extras to be added to an intent launched to this target.

Returns
Bundle the extras to merge with the extras of the intent being launched

getScore

Added in API level 23
public float getScore ()

Returns the ranking score supplied by the creator of this ChooserTarget. Values are between 0.0f and 1.0f. The UI displaying the target may take this score into account when sorting and merging targets from multiple sources.

Returns
float the ranking score for this target between 0.0f and 1.0f, inclusive

getTitle

Added in API level 23
public CharSequence getTitle ()

Returns the title of this target for display to a user. The UI displaying the title may truncate this title if it is too long to be displayed in full.

Returns
CharSequence the title of this target, intended to be shown to a user

toString

Added in API level 23
public String toString ()

Returns a string representation of the object.

Returns
String a string representation of the object.

writeToParcel

Added in API level 23
public void writeToParcel (Parcel dest, 
                int flags)

Flatten this object in to a Parcel.

Parameters
dest Parcel: The Parcel in which the object should be written. This value cannot be null.

flags int: Additional flags about how the object should be written. May be 0 or Parcelable.PARCELABLE_WRITE_RETURN_VALUE. Value is either 0 or a combination of Parcelable.PARCELABLE_WRITE_RETURN_VALUE, and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES