We have a text view which supports HTML tags. In this text view, the text will come in the form of HTML and we are able to populate it perfectly. The text may contain, some hyperlinks. These hyperlinks are in regular <a href>
tags.
The catch here is that these hyperlinks may be outside URLs or reference path to internal Activities.
The functionality works fine. But during Talkback feature, the internal paths are not calling the onClick method to call respective intents and throws an error
Error
W/URLSpan: Actvity was not found for intent, Intent { act=android.intent.action.VIEW dat=/abc/xyz/CONTACT_US (has extras) }
The below code is our handler to capture onClick and open the respective page. But this method is not firing during talkback. Rather, the URL is taken from the text itself. Is there a way to override talkback to use our method?
Code for the method to handle hyperlink clicks.
CustomLinkMovementMethod.linkify(Linkify.ALL, text)
.setOnLinkClickListener(new CustomLinkMovementMethod.OnLinkClickListener() {
@Override
public boolean onClick(TextView textView, String url) {
Log.d(TAG, "onClick: " + url);
if (mContext instanceof Activity) {
((Activity)mContext).handleLink( url );
}
return false;
}
});
I removed the CustomLinkMovementMethod and in its place used a Custom URLSpan class to capture hyperlinks embedded in the HTML texts
Custom URL Span class is similar to the accepted answer in the following StackOverflow question