TextLinks
  public
  
  final
  
  class
  TextLinks
  
    extends Object
  
  
  
  
  
      implements
      
        Parcelable
      
  
  
| java.lang.Object | |
| ↳ | android.view.textclassifier.TextLinks | 
A collection of links, representing subsequences of text and the entity types (phone number, address, url, etc) they may be.
Summary
| Nested classes | |
|---|---|
| 
        
        
        
        
        class | TextLinks.BuilderA builder to construct a TextLinks instance. | 
| 
        
        
        
        
        class | TextLinks.RequestA request object for generating TextLinks. | 
| 
        
        
        
        
        class | TextLinks.TextLinkA link, identifying a substring of text and possible entity types for it. | 
| 
        
        
        
        
        class | TextLinks.TextLinkSpanA ClickableSpan for a TextLink. | 
| Constants | |
|---|---|
| int | APPLY_STRATEGY_IGNOREDo not replace  | 
| int | APPLY_STRATEGY_REPLACEReplace any  | 
| int | STATUS_DIFFERENT_TEXTThe specified text does not match the text used to generate the links. | 
| int | STATUS_LINKS_APPLIEDLinks were successfully applied to the text. | 
| int | STATUS_NO_LINKS_APPLIEDNo links applied to text. | 
| int | STATUS_NO_LINKS_FOUNDNo links exist to apply to text. | 
| int | STATUS_UNSUPPORTED_CHARACTERThe specified text contains unsupported characters. | 
| Inherited constants | 
|---|
| Fields | |
|---|---|
| 
    public
    static
    final
    Creator<TextLinks> | CREATOR
 | 
| Public methods | |
|---|---|
| 
        
        
        
        
        
        int | 
      apply(Spannable text, int applyStrategy, Function<TextLinks.TextLink, TextLinks.TextLinkSpan> spanFactory)
      Annotates the given text with the generated links. | 
| 
        
        
        
        
        
        int | 
      describeContents()
      Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. | 
| 
        
        
        
        
        
        Bundle | 
      getExtras()
      Returns the extended data. | 
| 
        
        
        
        
        
        Collection<TextLinks.TextLink> | 
      getLinks()
      Returns an unmodifiable Collection of the links. | 
| 
        
        
        
        
        
        CharSequence | 
      getText()
      Returns the text that was used to generate these links. | 
| 
        
        
        
        
        
        String | 
      toString()
      Returns a string representation of the object. | 
| 
        
        
        
        
        
        void | 
      writeToParcel(Parcel dest, int flags)
      Flatten this object in to a Parcel. | 
| Inherited methods | |
|---|---|
Constants
APPLY_STRATEGY_IGNORE
public static final int APPLY_STRATEGY_IGNORE
Do not replace ClickableSpans that exist where the TextLinkSpan needs to
 be applied to. Do not apply the TextLinkSpan.
Constant Value: 0 (0x00000000)
APPLY_STRATEGY_REPLACE
public static final int APPLY_STRATEGY_REPLACE
Replace any ClickableSpans that exist where the TextLinkSpan needs to be
 applied to.
Constant Value: 1 (0x00000001)
STATUS_DIFFERENT_TEXT
public static final int STATUS_DIFFERENT_TEXT
The specified text does not match the text used to generate the links.
Constant Value: 3 (0x00000003)
STATUS_LINKS_APPLIED
public static final int STATUS_LINKS_APPLIED
Links were successfully applied to the text.
Constant Value: 0 (0x00000000)
STATUS_NO_LINKS_APPLIED
public static final int STATUS_NO_LINKS_APPLIED
No links applied to text. The links were filtered out.
Constant Value: 2 (0x00000002)
STATUS_NO_LINKS_FOUND
public static final int STATUS_NO_LINKS_FOUND
No links exist to apply to text. Links count is zero.
Constant Value: 1 (0x00000001)
STATUS_UNSUPPORTED_CHARACTER
public static final int STATUS_UNSUPPORTED_CHARACTER
The specified text contains unsupported characters.
Constant Value: 4 (0x00000004)
Fields
Public methods
apply
public int apply (Spannable text, int applyStrategy, Function<TextLinks.TextLink, TextLinks.TextLinkSpan> spanFactory)
Annotates the given text with the generated links. It will fail if the provided text doesn't match the original text used to create the TextLinks.
NOTE: It may be necessary to set a LinkMovementMethod on the TextView
 widget to properly handle links. See TextView.setMovementMethod(MovementMethod)
| Parameters | |
|---|---|
| text | Spannable: the text to apply the links to. Must match the original text
 This value cannot benull. | 
| applyStrategy | int: the apply strategy used to determine how to apply links to text.
      e.gTextLinks.APPLY_STRATEGY_IGNOREValue isAPPLY_STRATEGY_IGNORE, orAPPLY_STRATEGY_REPLACE | 
| spanFactory | Function: a custom span factory for converting TextLinks to TextLinkSpans.
      Set tonullto use the default span factory. | 
| Returns | |
|---|---|
| int | a status code indicating whether or not the links were successfully applied
      e.g. STATUS_LINKS_APPLIEDValue isSTATUS_LINKS_APPLIED,STATUS_NO_LINKS_FOUND,STATUS_NO_LINKS_APPLIED,STATUS_DIFFERENT_TEXT, orSTATUS_UNSUPPORTED_CHARACTER | 
describeContents
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 0orCONTENTS_FILE_DESCRIPTOR | 
getExtras
public Bundle getExtras ()
Returns the extended data.
NOTE: Do not modify this bundle.
| Returns | |
|---|---|
| Bundle | This value cannot be null. | 
getLinks
public Collection<TextLinks.TextLink> getLinks ()
Returns an unmodifiable Collection of the links.
| Returns | |
|---|---|
| Collection<TextLinks.TextLink> | This value cannot be null. | 
getText
public CharSequence getText ()
Returns the text that was used to generate these links.
| Returns | |
|---|---|
| CharSequence | This value cannot be null. | 
toString
public String toString ()
Returns a string representation of the object.
| Returns | |
|---|---|
| String | a string representation of the object. | 
writeToParcel
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 benull. | 
| flags | int: Additional flags about how the object should be written.
 May be 0 orParcelable.PARCELABLE_WRITE_RETURN_VALUE.
 Value is either0or a combination ofParcelable.PARCELABLE_WRITE_RETURN_VALUE, and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES | 
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
