Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open links in Android app in external browser?

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.

like image 949
Saurabh Alang Avatar asked Jun 19 '15 18:06

Saurabh Alang


3 Answers

Something like this could work

Intent browserIntent = new Intent(Intent.ACTION_VIEW,   
Uri.parse("http://www.google.com"));
startActivity(browserIntent);
like image 53
Zain Avatar answered Oct 15 '22 15:10

Zain


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

like image 23
kishorsinghgour Avatar answered Oct 15 '22 15:10

kishorsinghgour


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);
like image 38
Dhina k Avatar answered Oct 15 '22 17:10

Dhina k