我目前有一个带有一些 HTML 电话号码和 url 的 TextView。
我注意到我们可以使用 setMovementMethod 使这些链接可点击:
tv.setText("Phone number is: +32485123456 and url is http://www.blabla.com");
tv.setMovementMethod(LinkMovementMethod.getInstance());
这很好用,但在某些设备上,它会因 ActivityNotFoundException 而崩溃,这是可以理解的。(见下面的代码)
这些问题出现在我的开发者控制台中,我无法重现它们。
我面临的最大问题是我无法在我的活动中尝试/捕获代码,因为点击是由 LinkMovementMethod 处理的
关于如何避免此类错误的任何想法?
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=www.vlaamsbrabant.be/zoutleeuw (has extras) }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1408)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
at android.app.Activity.startActivityForResult(Activity.java:2817)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:817)
at android.app.Activity.startActivity(Activity.java:2923)
at android.text.style.URLSpan.onClick(URLSpan.java:62)
at android.text.method.LinkMovementMethod.onTouchEvent(LinkMovementMethod.java:216)
at android.widget.TextView.onTouchEvent(TextView.java:6788)
at android.view.View.dispatchTouchEvent(View.java:3766)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1896)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1159)
at android.app.Activity.dispatchTouchEvent(Activity.java:2086)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1880)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1811)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)