0

My application is kind of a social app. My problem is that if someone uploads a text with a link in it, the app doesn't recognize the link and the link isn't clickable.

I thought to myself that maybe there is a simple way to make my app recognize a link and make it clickable.

Gilad Neiger
  • 643
  • 1
  • 6
  • 15
  • If you're showing the links in a TextView or something, it has an attribute called autoLink which you can set to all or link `android:autoLink="all"` – Vucko Jun 18 '16 at 16:38

1 Answers1

1

You can use this code for auto detecting in string.

String originalString = "Please go to http://www.stackoverflow.com";
String newString = originalString.replaceAll("http://.+?(com|net|org)/{0,1}", "<a href=\"$0\">$0</a>");

Resource Link:

How to detect the presence of URL in a string

UPDATE1:

Enabling support for one of Android’s default link patterns is very easy. Simply use the addLinks(TextView text, int mask) function and specify a mask that describes the desired link types.

import android.text.util.Linkify;

// Recognize phone numbers and web URLs
Linkify.addLinks(text, Linkify.PHONE_NUMBERS | Linkify.WEB_URLS);

// Recognize all of the default link text patterns 
Linkify.addLinks(text, Linkify.ALL);

Resource Link:

  1. Android Text Links Using Linkify
  2. Linkify and autoLink Need a Custom URLSpan

For more details, you can go through this tutorial: Android Linkify both web and @mentions all in the same TextView

Community
  • 1
  • 1
SkyWalker
  • 28,384
  • 14
  • 74
  • 132
  • Hi, first thanks for your comment. Second, how do I use the code that is written in the link you've written? I've added the class, but how do I use it? – Gilad Neiger Jun 18 '16 at 17:52