2012-12-03 2 views
3

안드로이드 앱에서 TextViewandroid:autoLinkweb으로 설정하면 클릭 링크가 가능합니다. 내 HTC에이를 실행한다면 욕망 나는 다음과 같은 예외를 클래스 내 빌드 경로에없는 것처럼 HtcLinkifyDispatcherActivity이 곳 저를 얻을 등록자동 링크가 HTC에서 작동하지 않습니다. - HtcLinkifyDispatcher

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) 

시도를 얻을 링크 중 하나를 탭하면 ICS로 업그레이드 (S) .

+0

[문제 39682] (https://code.google.com/p/android/issues/detail?id=39682)이 문제의 관련 버그 리포트 인 것 같습니다. – JJD

답변

10

내가 가장 관련있는 문서는 The Linkify Problem: The Detection and the Mitigation입니다.

는하지만, 오히려 차단하고 URLSpan 클래스를 대체하는 것보다, 나는 수준 낮은 가서 텍스트 뷰의 부모 활동에 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)); 
    } 
} 

단순하지만 해키가 작동하는 것처럼 보입니다.

+1

그것은 활동을 시작하는 방법 인 경우에만 작동합니다. 'Context'가 액티비티를 시작할 수 있기 때문에, 개발자는 다른 인터 텍스트 (예를 들어, Interwebs를 범람하는'getApplicationContext()'정크)를 사용할 수 있습니다. 나는'createChooser()'가 이미'Intent'에 이미 지정된 구성 요소를 일관되게 무시할 것이라는 점도 조금 신경이 쓰이지 만,'setComponent (null)'을 호출하여이를 지우는 것이 좋습니다. – CommonsWare

+0

나는이 작은 응용 프로그램에서 일하는 유일한 개발자가 될 것이고 나는'autolink'보다 더 멋진 것을하려고하지 않을 것이다. 이것은 나를위한 합리적인 해결책이 될 것이다. –

+0

'startActivity()'를 호출하기 전에'setComponent (null)'을 호출하는 것보다 더 재미있게 놀았습니다. 그것은 악의적 인'HtcLinkifyDispatcher'를 완전히 없애고 선택자를 보여주지 않고 예상대로 기본 브라우저를 시작합니다. 내 초 안전 구현을 반영하기 위해 코드 샘플을 내 대답에 업데이트했습니다. –