Class Linkify

java.lang.Object
com.codename1.util.Linkify

public final class Linkify extends Object

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

String message = "Write to support@example.com 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.

  • Field Details

  • Method Details

    • find

      public static List<Linkify.Link> find(String text)

      Finds every kind of link in a text.

      Parameters
      • text: 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: the text to search
      • types: URL, EMAIL and PHONE or-ed together
      Returns

      the links in the order they appear