3

我在我的 Android 应用程序中使用set android:autoLinkto来启用可点击链接。但是,如果我在升级到 ICS 的 HTC Desire S 上运行它,当我点击其中一个链接时,会出现以下异常webTextView

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

4

1 回答 1

11

我发现与此相关的最好的文章是Linkify 问题:检测和缓解

但是,我没有尝试拦截和替换URLSpan该类,而是降低了一个级别并覆盖了startActivity()TextView 的父 Activity。

@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));
    }
}

哈克但简单,似乎工作。

于 2012-12-03T20:35:18.550 回答