0

Why, with this approach, we will only use the last pattern:

Linkify.addLinks(someSpannable, Linkify.PHONE_NUMBERS)
Linkify.addLinks(someSpannable, Linkify.EMAIL_ADDRESSES)

In this case, both phone and email links will be highlighted:

Linkify.addLinks(someSpannable, Patterns.PHONE, null)
Linkify.addLinks(someSpannable, Patterns.EMAIL_ADDRESS, null)
Funrab
  • 83
  • 1
  • 10

1 Answers1

0

Based on the documentation: https://developer.android.com/reference/android/text/util/Linkify#addLinks(android.text.Spannable,%20int)

public static final boolean addLinks (Spannable text, int mask)

Scans the text of the provided Spannable and turns all occurrences of the link types indicated in the mask into clickable links. If the mask is nonzero, it also removes any existing URLSpans attached to the Spannable, to avoid problems if you call it repeatedly on the same text.

in the other hand https://developer.android.com/reference/android/text/util/Linkify#addLinks(android.text.Spannable,%20int,%20java.util.function.Function%3Cjava.lang.String,%20android.text.style.URLSpan%3E)

public static final boolean addLinks (Spannable text, 
            int mask, 
            Function<String, URLSpan> urlSpanFactory)

Scans the text of the provided Spannable and turns all occurrences of the link types indicated in the mask into clickable links. If the mask is nonzero, it also removes any existing URLSpans attached to the Spannable, to avoid problems if you call it repeatedly on the same text.

hakim
  • 3,819
  • 3
  • 21
  • 25
  • You can clarify. I understood correctly that there should be no differences. I can see the differences when I run my code. In the case of patterns, UrlSpans are not deleted. – Funrab Jun 02 '21 at 20:39