我在Android应用中的android:autoLink
上使用web
设置为TextView
以启用可点击链接。但如果我在我的HTC Desire S升级到ICS上运行此操作,当我点击其中一个链接时,我会得到以下异常
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)
尝试注册HtcLinkifyDispatcherActivity
让我无处可去,因为课程不在我的构建路径上。
答案 0 :(得分:10)
我发现与此相关的最佳文章是The Linkify Problem: The Detection and the Mitigation。
但是,我没有尝试拦截和替换URLSpan
类,而是降低了一级,并覆盖了TextView的父Activity上的startActivity()
。
@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但很简单,似乎也有效。