【发布时间】:2014-10-28 20:19:12
【问题描述】:
我的应用程序允许用户在使用有限的 HTML 时向其他用户键入消息。我允许的其中一件事是使用超链接。
例子:
<a href="www.google.com">Google</a>
我正在通过以下方法填充TextView:
txtview.setMovementMethod(LinkMovementMethod.getInstance());
txtview.setText(Html.fromHtml(items.get(position).getBody()));
如果用户创建的超链接没有在 url 前加上 http 前缀,应用程序会崩溃并出现以下异常:
FATAL EXCEPTION: main
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=www.google.com (has extras) }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1545)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1416)
如果网址以http 为前缀,则一切正常。
例子:
<a href="http://www.google.com">Google</a>
如何防止这种情况发生?
【问题讨论】: