3

クリック可能なリンクを有効にするために、Android アプリでandroid:autoLinkset towebを使用しています。TextViewしかし、ICS にアップグレードされた HTC Desire S でこれを実行すると、リンクの 1 つをタップすると、次の例外が発生します。

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

これに関連して私が見つけた最良の記事は、The Linkify Problem: The Detection and the Mitigationです。

しかし、クラスをインターセプトして置き換えようとするのではなくURLSpan、レベルを下げstartActivity()て 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));
    }
}

ハッキーだがシンプルで、うまくいくようだ。

于 2012-12-03T20:35:18.550 に答える