Having the textView with autoLinkMask
set to Linkify.ALL
, i'm able to open the links and the browser shows the web-page.
I need to call another activity that will do it with it's webView not leaving the application.
Important notes:
- changing the textView content is not an option, i need to have the links displayed as they are with the schemes they have,
- there's lot of text in the textView, not only the link.
I looked through movementMethod
and IntentFilters
, might miss something but looks like it can't help.
So, any option to intercept the touched link in the TextView
to do something with it not opening the browser ?
If you want to mention this SO question, please give some arguments why cause it doesn't seem to solve the same problem as I have.
I make @CommonsWare's code more elegant and clear by adding Click Listener which can be added directly into the same method which replace URL Spans.
Define
YourCustomClickableSpan Class
.Define
RichTextUtils Class
which will manipulate the Spanned text of your TextView.Define
URLSpanConverter class
which will do the actual code of replacement URLSpan with Your Custom Span.Usage
Note that I defined all classes here as static so you can put it directly info your Util class and then reference it easily from any place.
Just to share an alternative solution using Textoo that I just created:
Under the hood the library replace
URLSpan
's in the TextView with customClickableSpan
implementation that dispatch click events to the user suppliedLinksHandler
(s). The mechanism is very similar to solution from @commonsWare. Just package in a higher level API to make it easier to use.Than do this:
onCreate of WebActivity Class:
Add this under textview in xml:
I think David Hedlund's answer to himself is the way to go. In my case I had a TextView containing SMS content form user's inbox and I wanted to handle the fallowing behaviour:
To achieve this I used the linked answer in this way:
Now in the manifest:
And it works just fine for me, when user clicks a phone number the picker will show up with the dialer/address book choice. In the called activities use
getIntent().getData()
to find the passed Url with the data in it.Step #1: Create your own subclass of
ClickableSpan
that does what you want in itsonClick()
method (e.g., calledYourCustomClickableSpan
)Step #2: Run a bulk conversion of all of the
URLSpan
objects to beYourCustomClickableSpan
objects. I have a utility class for this:You would use it like this:
with a custom
URLSpanConverter
like this:to convert all
URLSpan
objects toYourCustomClickableSpan
objects.