# LinkifyCompat

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/text/util/LinkifyCompat.java+class:androidx.core.text.util.LinkifyCompat) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

*** ** * ** ***


```
public final class LinkifyCompat
```

<br />

*** ** * ** ***

LinkifyCompat brings in `Linkify` improvements for URLs and email addresses to older API levels.

## Summary

| ### Public methods |
|---|---|
| `static boolean` | `https://developer.android.com/reference/androidx/core/text/util/LinkifyCompat#addLinks(android.text.Spannable,int)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/text/Spannable.html 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. |
| `static boolean` | `https://developer.android.com/reference/androidx/core/text/util/LinkifyCompat#addLinks(android.widget.TextView,int)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/widget/TextView.html text, int mask)` Scans the text of the provided TextView and turns all occurrences of the link types indicated in the mask into clickable links. |
| `static boolean` | `https://developer.android.com/reference/androidx/core/text/util/LinkifyCompat#addLinks(android.text.Spannable,java.util.regex.Pattern,java.lang.String)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/text/Spannable.html text, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/regex/Pattern.html pattern, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html scheme )` Applies a regex to a Spannable turning the matches into links. |
| `static void` | `https://developer.android.com/reference/androidx/core/text/util/LinkifyCompat#addLinks(android.widget.TextView,java.util.regex.Pattern,java.lang.String)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/widget/TextView.html text, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/regex/Pattern.html pattern, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html scheme )` Applies a regex to the text of a TextView turning the matches into links. |
| `static boolean` | `https://developer.android.com/reference/androidx/core/text/util/LinkifyCompat#addLinks(android.text.Spannable,java.util.regex.Pattern,java.lang.String,android.text.util.Linkify.MatchFilter,android.text.util.Linkify.TransformFilter)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/text/Spannable.html spannable, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/regex/Pattern.html pattern, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html scheme, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/text/util/Linkify.MatchFilter.html matchFilter, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/text/util/Linkify.TransformFilter.html transformFilter )` Applies a regex to a Spannable turning the matches into links. |
| `static void` | `https://developer.android.com/reference/androidx/core/text/util/LinkifyCompat#addLinks(android.widget.TextView,java.util.regex.Pattern,java.lang.String,android.text.util.Linkify.MatchFilter,android.text.util.Linkify.TransformFilter)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/widget/TextView.html text, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/regex/Pattern.html pattern, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html scheme, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/text/util/Linkify.MatchFilter.html matchFilter, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/text/util/Linkify.TransformFilter.html transformFilter )` Applies a regex to the text of a TextView turning the matches into links. |
| `static boolean` | `https://developer.android.com/reference/androidx/core/text/util/LinkifyCompat#addLinks(android.text.Spannable,java.util.regex.Pattern,java.lang.String,java.lang.String[],android.text.util.Linkify.MatchFilter,android.text.util.Linkify.TransformFilter)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/text/Spannable.html spannable, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/regex/Pattern.html pattern, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html defaultScheme, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html String[] schemes, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/text/util/Linkify.MatchFilter.html matchFilter, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/text/util/Linkify.TransformFilter.html transformFilter )` Applies a regex to a Spannable turning the matches into links. |
| `static void` | `https://developer.android.com/reference/androidx/core/text/util/LinkifyCompat#addLinks(android.widget.TextView,java.util.regex.Pattern,java.lang.String,java.lang.String[],android.text.util.Linkify.MatchFilter,android.text.util.Linkify.TransformFilter)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/widget/TextView.html text, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/regex/Pattern.html pattern, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html defaultScheme, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html String[] schemes, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/text/util/Linkify.MatchFilter.html matchFilter, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/text/util/Linkify.TransformFilter.html transformFilter )` Applies a regex to the text of a TextView turning the matches into links. |

## Public methods

### addLinks

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
public static boolean addLinks(@NonNull 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.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/text/Spannable.html text` | Spannable whose text is to be marked-up with links |
| `int mask` | Mask to define which kinds of links will be searched. Value is either `0` or a combination of the following: - `Linkify.WEB_URLS` - `Linkify.EMAIL_ADDRESSES` - `Linkify.PHONE_NUMBERS` - `Linkify.MAP_ADDRESSES` - `Linkify.ALL` <br /> |

| Returns |
|---|---|
| `boolean` | True if at least one link is found and applied. |

### addLinks

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
public static boolean addLinks(@NonNull TextView text, int mask)
```

Scans the text of the provided TextView and turns all occurrences of the link types indicated in the mask into clickable links. If matches are found the movement method for the TextView is set to LinkMovementMethod.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/widget/TextView.html text` | TextView whose text is to be marked-up with links |
| `int mask` | Mask to define which kinds of links will be searched. Value is either `0` or a combination of the following: - `Linkify.WEB_URLS` - `Linkify.EMAIL_ADDRESSES` - `Linkify.PHONE_NUMBERS` - `Linkify.MAP_ADDRESSES` - `Linkify.ALL` <br /> |

| Returns |
|---|---|
| `boolean` | True if at least one link is found and applied. |

### addLinks

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
public static boolean addLinks(
    @NonNull Spannable text,
    @NonNull Pattern pattern,
    @Nullable String scheme
)
```

Applies a regex to a Spannable turning the matches into links.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/text/Spannable.html text` | Spannable whose text is to be marked-up with links |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/regex/Pattern.html pattern` | Regex pattern to be used for finding links |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html scheme` | URL scheme string (eg `http://`) to be prepended to the links that do not start with this scheme. |

### addLinks

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
public static void addLinks(
    @NonNull TextView text,
    @NonNull Pattern pattern,
    @Nullable String scheme
)
```

Applies a regex to the text of a TextView turning the matches into links. If links are found then UrlSpans are applied to the link text match areas, and the movement method for the text is changed to LinkMovementMethod.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/widget/TextView.html text` | TextView whose text is to be marked-up with links |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/regex/Pattern.html pattern` | Regex pattern to be used for finding links |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html scheme` | URL scheme string (eg `http://`) to be prepended to the links that do not start with this scheme. |

### addLinks

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
public static boolean addLinks(
    @NonNull Spannable spannable,
    @NonNull Pattern pattern,
    @Nullable String scheme,
    @Nullable Linkify.MatchFilter matchFilter,
    @Nullable Linkify.TransformFilter transformFilter
)
```

Applies a regex to a Spannable turning the matches into links.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/text/Spannable.html spannable` | Spannable whose text is to be marked-up with links |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/regex/Pattern.html pattern` | Regex pattern to be used for finding links |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html scheme` | URL scheme string (eg `http://`) to be prepended to the links that do not start with this scheme. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/text/util/Linkify.MatchFilter.html matchFilter` | The filter that is used to allow the client code additional control over which pattern matches are to be converted into links. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/text/util/Linkify.TransformFilter.html transformFilter` | Filter to allow the client code to update the link found. |

| Returns |
|---|---|
| `boolean` | True if at least one link is found and applied. |

### addLinks

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
public static void addLinks(
    @NonNull TextView text,
    @NonNull Pattern pattern,
    @Nullable String scheme,
    @Nullable Linkify.MatchFilter matchFilter,
    @Nullable Linkify.TransformFilter transformFilter
)
```

Applies a regex to the text of a TextView turning the matches into links. If links are found then UrlSpans are applied to the link text match areas, and the movement method for the text is changed to LinkMovementMethod.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/widget/TextView.html text` | TextView whose text is to be marked-up with links |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/regex/Pattern.html pattern` | Regex pattern to be used for finding links |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html scheme` | URL scheme string (eg `http://`) to be prepended to the links that do not start with this scheme. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/text/util/Linkify.MatchFilter.html matchFilter` | The filter that is used to allow the client code additional control over which pattern matches are to be converted into links. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/text/util/Linkify.TransformFilter.html transformFilter` | Filter to allow the client code to update the link found. |

### addLinks

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
public static boolean addLinks(
    @NonNull Spannable spannable,
    @NonNull Pattern pattern,
    @Nullable String defaultScheme,
    @Nullable String[] schemes,
    @Nullable Linkify.MatchFilter matchFilter,
    @Nullable Linkify.TransformFilter transformFilter
)
```

Applies a regex to a Spannable turning the matches into links.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/text/Spannable.html spannable` | Spannable whose text is to be marked-up with links. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/regex/Pattern.html pattern` | Regex pattern to be used for finding links. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html defaultScheme` | The default scheme to be prepended to links if the link does not start with one of the `schemes` given. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html String[] schemes` | Array of schemes (eg `http://`) to check if the link found contains a scheme. Passing a null or empty value means prepend defaultScheme to all links. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/text/util/Linkify.MatchFilter.html matchFilter` | The filter that is used to allow the client code additional control over which pattern matches are to be converted into links. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/text/util/Linkify.TransformFilter.html transformFilter` | Filter to allow the client code to update the link found. |

| Returns |
|---|---|
| `boolean` | True if at least one link is found and applied. |

### addLinks

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
public static void addLinks(
    @NonNull TextView text,
    @NonNull Pattern pattern,
    @Nullable String defaultScheme,
    @Nullable String[] schemes,
    @Nullable Linkify.MatchFilter matchFilter,
    @Nullable Linkify.TransformFilter transformFilter
)
```

Applies a regex to the text of a TextView turning the matches into links. If links are found then UrlSpans are applied to the link text match areas, and the movement method for the text is changed to LinkMovementMethod.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/widget/TextView.html text` | TextView whose text is to be marked-up with links. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/regex/Pattern.html pattern` | Regex pattern to be used for finding links. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html defaultScheme` | The default scheme to be prepended to links if the link does not start with one of the `schemes` given. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html String[] schemes` | Array of schemes (eg `http://`) to check if the link found contains a scheme. Passing a null or empty value means prepend defaultScheme to all links. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/text/util/Linkify.MatchFilter.html matchFilter` | The filter that is used to allow the client code additional control over which pattern matches are to be converted into links. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/text/util/Linkify.TransformFilter.html transformFilter` | Filter to allow the client code to update the link found. |