6

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.

humazed
  • 74,687
  • 32
  • 99
  • 138
MithunRaj
  • 543
  • 2
  • 7
  • 19

3 Answers3

14

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

Omid Ziyaee
  • 420
  • 4
  • 16
Houcine
  • 24,001
  • 13
  • 56
  • 83
  • 1
    Thank you for your reply. But my requirement is that I want to display the IntentChooser even if there is only one browser application in the android device. Please advice. – MithunRaj Jul 01 '13 at 13:03
  • 1
    @MithunRaj you can create you own `IntentChooser` and retreive all browser apps in your device ( in this case it will be one application ), and then display it , see my edits – Houcine Jul 01 '13 at 13:22
3
Intent sendIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.maidofknowledge.com"));
            Intent chooser = Intent.createChooser(sendIntent, "Choose Your Browser");
            if (sendIntent.resolveActivity(getPackageManager()) != null) {
                startActivity(chooser);
            }
Saim Saddat
  • 38
  • 1
  • 1
  • 8
Md. Zakir Hossain
  • 1,082
  • 11
  • 24
-1

settings>apps>clear default (

this is if you have previously set "use as default app" for chrome

these 2 images are my source:

Message to select browser or select default: http://cdn2.ubergizmo.com/wp-content/uploads/2015/02/how-to-default-app-03.jpg

Clear default browser, show intent chooser again: http://cdn2.ubergizmo.com/wp-content/uploads/2015/02/how-to-default-app-02.jpg

googledit
  • 17
  • 1