My app allows users to type messages to other users while using limited HTML. One of the things I allow is the use of hyperlinks.
Example:
<a href="www.google.com">Google</a>
I am populating the TextView
via the following method:
txtview.setMovementMethod(LinkMovementMethod.getInstance());
txtview.setText(Html.fromHtml(items.get(position).getBody()));
If the user creates a hyperlink without prefixing http
to the url, the application crashes with the following exception:
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)
If the url is prefixed with http
, everything works fine.
Example:
<a href="http://www.google.com">Google</a>
How can I prevent this from happening?