Skip to content

Android Linkify

April 17, 2010

Hey everyone,

This isn’t really a full post – more just me ranting about something awesome I discovered recently.

In one of my applications (currently under development) I wanted to show users details about certain events/venues, and wanted to link addresses so that they would automatically pull up a GPS intent, and link phone numbers so that they would automatically pull up a phone call intent.I was prepared to spend some time ripping apart sample text with REGEX, and then manually linking them with the appropriate intents, but luckily the folks at Google had my back on this one and I ran into this nifty class Linkify.

This will be a short example on how to use Linkify (even though it’s pretty simple), but I thought writing a blog post on it would be useful since it seems like a pretty useful class in a lot of applications and I’m sure not many people know about it…

TextView addressText = (TextView) findViewById(R.id.event_address);
addressText.setText("436 Mayfield Ave, Stanford, CA");
Linkify.addLinks(addressText, Linkify.MAP_ADDRESSES);

TextView numberText = (TextView) findViewById(R.id.event_number);
numberText.setText("630-857-0720");
Linkify.addLinks(numberText, Linkify.PHONE_NUMBERS);

And that’s it! Run the Activity as you normally would and you should see that both text views are highlighted with all the correct intents built into it!

Happy coding,

– jwei

4 Comments leave one →
  1. October 12, 2010 2:56 am

    Thanks for your information.!! 🙂

  2. ashish Dwivedi permalink
    June 28, 2011 5:25 am

    Thanks but I want to know more about Linkify class

  3. August 9, 2011 12:47 pm

    Way cool, thanks Jason! Actually, loving the blog as a whole, super helpful 🙂

  4. Antonio permalink
    September 7, 2011 1:48 pm

    Excelent!!!! Thanks 😉

Leave a comment