How to open links in Android app in external browser?

10,184

Solution 1

Something like this could work

Intent browserIntent = new Intent(Intent.ACTION_VIEW,   
Uri.parse("http://www.google.com"));
startActivity(browserIntent);

Solution 2

As @zain posted ago you can use.

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.stackoverflow.com"));
startActivity(intent); 

But if you have more then one browser installed in device and want to choose from one of them. Use intent chooser like this

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.stackoverflow.com"));

// Always use string resources for UI text. This says something like "Share this photo with"
String title = getResources().getText(R.string.chooser_title);
// Create and start the chooser
Intent chooser = Intent.createChooser(intent, title);
startActivity(chooser);

refer from here Show browser list when opening a link in android

Solution 3

enter image description here

            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.google.co.in/"));


            String title = "Complete Action Using";

            Intent chooser = Intent.createChooser(intent, title);
            startActivity(chooser);
Share:
10,184
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    Can anyone help me in Code for opening links in external browsers or other Android app?

    Now the case is the link is opening in the app itself. But if the link belongs to an android app its not opening. It's showing install the Android app.

    So I want that if the link can be opened in browsers, then it will ask from a list of browsers. Or if the links belongs to an app it must show the app in the list too.

  • Forrest
    Forrest over 3 years
    This was great and still works fine despite being an old answer. Thanks One note - you will need to start activity from context if outside of a Fragment context.startActivity(chooser)