How to open links in Android app in external browser?

13.5k Views Asked by At

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.

4

There are 4 best solutions below

0
On

Something like this could work

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

If you are in a WebView in your App, and on clivking a link there, if the app opens the link in the App Itself, Then possibly u should have overridden this method.

 myWebView.setWebViewClient(new WebViewClient()       
    {
         @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) 
        {
            //view.loadUrl(url);

            return false;
        }
    });

The return of false should ask the user, where to Open the link. With the browsers installed in the mobile

1
On

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

0
On

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);