I am using android:autoLink
set to web
on a TextView
in my Android app to enable clickable links. But if I run this on my HTC Desire S upgraded to ICS, when I tap on one of the links I get the following exception
android.content.ActivityNotFoundException: Unable to find explicit activity class
{com.htc.HtcLinkifyDispatcher/
com.htc.HtcLinkifyDispatcher.HtcLinkifyDispatcherActivity};
have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1634)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1510)
at android.app.Activity.startActivityFromChild(Activity.java:3519)
at android.app.Activity.startActivityForResult(Activity.java:3271)
at android.app.Activity.startActivity(Activity.java:3358)
at woodsie.avalanche.info.InfoActivity.startActivity(InfoActivity.java:61)
at android.text.style.LinkifyURLSpan.onClick(LinkifyURLSpan.java:73)
Attempts to register HtcLinkifyDispatcherActivity
get me nowhere as the class is not on my build path.
The best article I found relating to this was The Linkify Problem: The Detection and the Mitigation.
But, rather than trying to intercept and replace the URLSpan
class, I went a level lower and overrode the startActivity()
on the parent Activity of the TextView.
@Override
public void startActivity(Intent intent) {
try {
/* First attempt at fixing an HTC broken by evil Apple patents. */
if (intent.getComponent() != null
&& ".HtcLinkifyDispatcherActivity".equals(intent.getComponent().getShortClassName()))
intent.setComponent(null);
super.startActivity(intent);
} catch (ActivityNotFoundException e) {
/*
* Probably an HTC broken by evil Apple patents. This is not perfect,
* but better than crashing the whole application.
*/
super.startActivity(Intent.createChooser(intent, null));
}
}
Hacky but simple, and seems to work.