2014-11-04 9 views
4

: // 접두사어떤 활동이 유효 http로 (브라우저)를 찾을 수 없습니다 다음과 같이 그래서 난 내 응용 프로그램에서 예외를 가지고

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=http://google.com (has extras) } 
    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1512) 
    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384) 
    at android.app.Activity.startActivityForResult(Activity.java:3248) 
    at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:839) 
    at android.app.Activity.startActivity(Activity.java:3359) 
    at android.text.style.URLSpan.onClick(URLSpan.java:62) 
    at android.text.method.LinkMovementMethod.onTouchEvent(LinkMovementMethod.java:212) 
    at android.widget.TextView.onTouchEvent(TextView.java:8704) 
    at android.view.View.dispatchTouchEvent(View.java:5556) 
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957) 
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726) 
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957) 
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726) 
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957) 
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726) 
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957) 
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726) 
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957) 
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726) 
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957) 
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726) 
    at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1940) 
    at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1390) 
    at android.app.Activity.dispatchTouchEvent(Activity.java:2414) 
    at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1888) 
    at android.view.View.dispatchPointerEvent(View.java:5736) 
    at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3017) 
    at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2582) 
    at android.view.ViewRootImpl.processInputEvents(ViewRootImpl.java:887) 
    at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2591) 
    at android.os.Handler.dispatchMessage(Handler.java:99) 
    at android.os.Looper.loop(Looper.java:137) 
    at android.app.ActivityThread.main(ActivityThread.java:4697) 
    at java.lang.reflect.Method.invokeNative(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:511) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554) 
    at dalvik.system.NativeStart.main(Native Method) 

이 내 코드로 연결되지 않습니다. 나는 사용자가 텍스트에서 URL을 클릭 할 때 (그리고 앱에 URL이있는 텍스트가있을 때) 발생한다고 가정합니다. 그것은 무엇에 관한 것인가? Android 기기에 브라우저가없는 것은 어떻게 될 수 있습니까? 이것을 우회하는 방법 또는 적어도 잡기 (텍스트에서 클릭 가능한 URL이 필요합니까?) 이 (CommonsWare의 기사 다음)하지만 내 URL이 완전히 남아

listView = (ListView) findViewById(R.id.listView); 
// empty pass list with clickable url inside 
final TextView listEmptyView = (TextView) findViewById(R.id.txtNoPasses); 
listEmptyView.setMovementMethod(LinkMovementMethod.getInstance()); 
listView.setEmptyView(listEmptyView); 

그래서 내가 시도 : UPDATE

사실 나는이 예외가 빈 목록보기 스텁 의도 된 텍스트 뷰에서 일어나는 것을 발견

listView = (ListView) findViewById(R.id.listView); 
    // empty pass list with clickable url inside 
    final TextView listEmptyView = (TextView) findViewById(R.id.txtNoPasses); 
    fixTextView(listEmptyView); 
    listView.setEmptyView(listEmptyView); 
} 

private void fixTextView(TextView textView) { 
    final SpannableString current = new SpannableString(textView.getText()); 
    final URLSpan[] spans = current.getSpans(0, current.length(), URLSpan.class); 
    int start, end; 
    for (URLSpan span : spans) { 
     start = current.getSpanStart(span); 
     end = current.getSpanEnd(span); 
     current.removeSpan(span); 
     current.setSpan(new DefensiveURLSpan(span.getURL()), start, end, 0); 
    } 
} 

private static class DefensiveURLSpan extends URLSpan { 
     public DefensiveURLSpan(String url) { 
     super(url); 
     } 

     @Override 
     public void onClick(View widget) { 
     try { 
      android.util.Log.d(getClass().getSimpleName(), "Got here!"); 
      super.onClick(widget); 
     } 
     catch (ActivityNotFoundException e) { 
      // do something useful here 
      // android.text.SpannedString cannot be cast to android.text.SpannableString 
     } 
     } 
} 

그리고 텍스트 뷰 :

,536,913,632이 경우 unclickable 10
<TextView 
     android:id="@+id/txtNoPasses" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 
     android:visibility="gone" 
     android:gravity="center" 
     android:padding="15dp" 
     android:text="@string/no_passes" 
     android:textAppearance="?android:attr/textAppearanceMedium"/> 

그리고 no_passes 문자열은 다음입니다 :

<string name="no_passes">Currently you have no cards to use.\n<a href="http://cardz.website.com">You could add some cards from our website</a></string> 

답변