autolink不能用于HTC - HtcLinkifyDispatcher

时间:2012-12-03 20:34:00

标签: android android-4.0-ice-cream-sandwich autolink commonsware

我在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让我无处可去,因为课程不在我的构建路径上。

1 个答案:

答案 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但很简单,似乎也有效。