Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get Linkified text from textview-android...?

I have a textview in my android application.

    textView.setText(message);
    Linkify.addLinks(textView, Linkify.ALL);

with this code it identify phone number,email address, weblink etc. and highlight it for click, so appropriate intent call.

I want to fetch whatever linkify in my textview store it in an array example

if my textview contains "Hello, this is deer, my phone number is 9988776655 and email id is [email protected] and weburl is www.abc.com" string

then I want to fetch "9988776655","[email protected]","www.abc.com" and store it in array, is it possible...!?!

like image 371
Manish Jain Avatar asked Feb 19 '23 16:02

Manish Jain


1 Answers

You can use TextView#getUrls after the call to Linkify like this:

URLSpan spans[] = textView.getUrls();
for(URLSpan span: spans) {
    Log.d(TAG, span.getURL());
}
like image 112
henrikpersson Avatar answered Feb 27 '23 09:02

henrikpersson