6

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.

Saurabh Alang
  • 61
  • 1
  • 1
  • 4

4 Answers4

8

Something like this could work

Intent browserIntent = new Intent(Intent.ACTION_VIEW,   
Uri.parse("http://www.google.com"));
startActivity(browserIntent);
Zain
  • 2,336
  • 1
  • 16
  • 25
4

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

Community
  • 1
  • 1
  • 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)` – Forrest Oct 23 '20 at 16:35
1

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);
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Dhina k
  • 1,481
  • 18
  • 24
-1

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

Prabhuraj
  • 928
  • 2
  • 8
  • 14