Arutha Arutha - 1 year ago 36
Android Question

How can I open a URL in Android's web browser from my application?

How to open an URL from code in the built-in web browser rather than within my application?

I tried this:

try {
Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(download_link));
} catch (ActivityNotFoundException e) {
Toast.makeText(this, "No application can handle this request."
+ " Please install a webbrowser", Toast.LENGTH_LONG).show();

but I got an Exception:

No activity found to handle Intent{action=android.intent.action.VIEW data


Try this:

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(""));

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://".