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:
- Android Text Links Using Linkify
- 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