0

I'm working on an Android Coursera assignment to open a link within a browser using Implicit Intents. Within the code, I have a chooser method that gives one the option of which browser they would like to use. The problem though is that no browser appears using the CATEGORY Browsable option. Please look at the my code:

private void startImplicitActivation() {

        Log.i(TAG, "Entered startImplicitActivation()");

        // TODO - Create a base intent for viewing a URL
        // (HINT:  second parameter uses Uri.parse())


        String url = "https://www.google.com";
        Intent baseIntent = new Intent(Intent.CATEGORY_BROWSABLE, Uri.parse(url));


        // TODO - Create a chooser intent, for choosing which Activity
        // will carry out the baseIntent
        // (HINT: Use the Intent class' createChooser() method)
        Intent chooserIntent = new Intent(Intent.createChooser(baseIntent, "Select Your Browser"));


        Log.i(TAG,"Chooser Intent Action:" + chooserIntent.getAction());


        // TODO - Start the chooser Activity, using the chooser intent
        startActivity(chooserIntent);


 }

The resulting output when launched in an activity is below (I don't understand why no browsers come up):

createChooser() method called with intent

Gurwinder Singh
  • 38,557
  • 6
  • 51
  • 76
  • 1
    Possible duplicate of [Sending an Intent to browser to open specific URL](http://stackoverflow.com/questions/3004515/sending-an-intent-to-browser-to-open-specific-url) – AxelH Jan 02 '17 at 06:32

1 Answers1

0

You can use this:

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("your url")); 
startActivity(intent);

I think the code directly opens the popup that which browsers is installed in your phone. You don't write specific code for that.

Pang
  • 9,564
  • 146
  • 81
  • 122
Pratik Gondil
  • 689
  • 1
  • 6
  • 17