Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public final class Linkify

  1. Object
  2. Linkify

Finds web addresses, email addresses and phone numbers in plain text.

String message = "Write to [email protected] or call +1 555 123 4567";
List<Linkify.Link> links = Linkify.find(message);
for (Linkify.Link l : links) {
    Log.p(l.getText() + " -> " + l.getUri());
}

A web address starts with http://, https:// or www., matched in any case. A bare domain such as example.com is not taken for one, so a sentence that names a file is left alone. Punctuation at the end of a match, such as the period ending a sentence, is not part of it. A phone number is 7 to 15 digits, optionally led by + and broken by spaces, dashes, dots or parentheses. SpanLabel.setAutoLink(true) makes the links in a label tappable.

Nested types

class Linkify.LinkA link found in a text.

Fields

public static final int URL = 1Web addresses.
public static final int EMAIL = 2Email addresses.
public static final int PHONE = 4Phone numbers.
public static final int ALL = 7Every kind.

Methods

public static List<Linkify.Link> find(String text)Finds every kind of link in a text.
public static List<Linkify.Link> find(String text, int types)Finds the links of some kinds in a text.

Inherited methods

Field details

URL

public static final int URL = 1
Web addresses.

EMAIL

public static final int EMAIL = 2
Email addresses.

PHONE

public static final int PHONE = 4
Phone numbers.

ALL

public static final int ALL = 7
Every kind.

Method details

find

public static List<Linkify.Link> find(String text)
Finds every kind of link in a text.

Parameters

text String
the text to search

Returns

the links in the order they appear

find

public static List<Linkify.Link> find(String text, int types)
Finds the links of some kinds in a text.

Parameters

text String
the text to search
types int
URL, EMAIL and PHONE or-ed together

Returns

the links in the order they appear