Starting a browser from a textbox via Intent - Is http:// required?

Posted by VitalyB on Stack Overflow See other posts from Stack Overflow or by VitalyB
Published on 2010-05-22T18:48:24Z Indexed on 2010/05/22 18:50 UTC
Read the original article Hit count: 209

Filed under:

Hi, I have the following code:

    /** Open a browser on the URL specified in the text box */
private void openBrowser() {
    Uri uri = Uri.parse(urlText.getText().toString());
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    startActivity(intent);
}

When I input "http://www.google.com" to the textbox, it works fine. However, when I try something like "www.google.com" it crashes with:

No Activity found to handle Intent { act=android.intent.action.VIEW dat=www.google.com }

Am I using Uri wrong? Is there a way to extract full address from it? Or am I supposed to write code that adds http manually? e.g, if not starts with http://, add http://.

Thanks!

© Stack Overflow or respective owner

Related posts about android