How to open an URL from code in the built-in web browser rather than within my application?
I tried this :
Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(strURL));
startActivity(myIntent);
but I got an Exception : "No activity found to handle Intent{action=android.intent.action.VIEW data =www.google.com"
Source: Tips4all
Try this:
ReplyDeleteIntent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(browserIntent);
That works fine for me.
As for the missing "http://" I'd just do something like this:
if (!url.startsWith("http://") && !url.startsWith("https://"))
url = "http://" + url;
I would also probably pre-populate your EditText that the user is typing a URL in with "http://".
In 2.3, I had better luck with
ReplyDeletefinal Intent intent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse(url));
activity.startActivity(intent);
The difference being the use of Intent.ACTION_VIEW rather than the String "android.intent.action.VIEW"