Sending an Intent to Browser to Open Specific Url

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

Try this:

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

Sending an Intent to browser to open specific URL

To open a URL/website you do the following:

String url = "http://www.example.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);

Here's the documentation of Intent.ACTION_VIEW.


Source: Opening a URL in Android's web browser from within application

Open intent in particular browser

You can open any url using specific browser by using its package but if browser not found in some device then have to handle exception.
Here,I am using chrome browser specifically to open this https://www.google.com

 Intent i=new Intent(ACTION_VIEW, Uri.parse("https://www.google.com"));
i.setPackage("com.android.chrome");
startActivity(i);

Note - I assume Chrome browser is available in device.

Intent for opening an URL doesn't work for one app but does for another

Actual issue is with the usage of Uri.encode(urlParam). You are encoding your URL but later you are not decoding it for the ACTION_VIEW to understand the intent data!

    String url = "https://www.google.com/";
String query = Uri.encode(url, "UTF-8");
Intent browserIntent = new Intent(CATEGORY_BROWSABLE, Uri.parse(Uri.decode(query)));
browserIntent.setAction(ACTION_VIEW);
startActivity(browserIntent);

Intent to open a link within a browser not working

You can use this:

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("your url")); 
startActivity(intent);

I think the code directly opens the popup that which browsers is installed in your phone. You don't write specific code for that.

How to Open a URL in New Activity's Webview by passing intent

You need to use i.putExtra(KEY, yourURL) instead of i.setData. You will need a key for that value.

And you will get it by the key in the new activity :

String url = (String) getIntent().getExtras().get(KEY);


Related Topics



Leave a reply



Submit