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开发者_如何学JAVA());
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!
Am I using Uri wrong?
No. However, www.google.com
is not a valid uniform resource identifier.
Or am I supposed to write code that adds http manually?
Yes.
精彩评论