Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show browser list when opening a link in android

I want to open some links in an external browser. Before opening, I want to display the list of browsers on the device. I did this functionality using Intent.ACTION_VIEW. But as per my app's requirement, I want to display the list of browsers even if there is only one browser application on the device. Does anyone have any idea about this? Thanks.

like image 865
MithunRaj Avatar asked Jul 01 '13 08:07

MithunRaj


People also ask

How do I change the way a link is open on Android?

To change how links open in Android, return to the Default apps page you visited earlier. Here, tap Opening links to review these settings. At the top, you can toggle the Instant apps feature, which allows you to use some apps without actually installing them.


1 Answers

If you have one browser application , the chooser will not launched , the URL will be loaded on that browser application. If you have two or more browser applications, the android system launch an IntentChooser the show the list of all browser apps installed on the device , so the user can choose his preferred browser to load the URL :

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

EDIT : to create your custom Intent Chooser :

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 = getString(R.string.chooser_title);
// Create and start the chooser
Intent chooser = Intent.createChooser(intent, title);
startActivity(chooser);

refer this

like image 53
Houcine Avatar answered Sep 28 '22 18:09

Houcine