The BROWSABLE category revealed

Assume that you on your desktop computer browse to a web page with the following page source

shit

Clicking on the first link you expect your browser to start a new tab and navigate to the url that was specified in the href. If you click on the second link you would expect that the browser opens up your favourite email client. The third link would probably just give you an error message since the browser has no idea how to react on a link like foo://my.test.com

On Android we can control how the device should react when the user clicks on a link in the web browser, or more specific control which Activity should be started. Every time the user clicks on a link the browser sends an intent to the platform with the following content.

action = android.intent.action.VIEW
category = android.intent.category.BROWSABLE
data = the text from the href tag

If we navigate to a web page with the following page source on our Andoid device we could expect a few interesting things to happen when we click on the links.

shit2

The first link will generate an intent with the following information

action = android.intent.action.VIEW
category = android.intent.category.BROWSABLE
data = "tel:123456"

This will start the Dialer application and preset the phone number to 123456.

device

Clicking on the second link will not surprisingly open up the email client in your device with a preset receiver address. What about clicking on the third link? Well, by default it would just return a “page not available” error message in the browser. The intent sent from the browser will look like this

action = android.intent.action.VIEW
category = android.intent.category.BROWSABLE
data = "foo://my.test.com"

This means that if we install an Activity with the following IntentFilter

intentfilter

this Activity will start when the user clicks on the third link. Pretty cool, isn’t it?

11 Comments

  1. Samuh Varta

    The intent mechanism used on the Android platform to start different activities is indeed cool! It allows different applications to interface with one another which if used cleverly, increases the number of use-cases applications can cater to.
    For e.g: http://android-developers.blogspot.com/2009/11/integrating-application-with-intents.html

  2. Akshata

    It is very nice article. I just want to ask one more question.. How we can pass the values to that application from same html page so that we can access these value in application

  3. Raheem

    great explanation by differentiating the html web and android web.
    thanks

  4. Is it possible to use the BROWSABLE category in a filter for a receiver or a service?

  5. Saravanan

    Hi ,

    A very good explanation, but I tried to launch the native app using the method specified in the link and it was not launching. In the LogCat, debug log , I could find the following line:

    06-02 12:02:10.658: INFO/ActivityManager(60): Starting: Intent { act=android.intent.action.VIEW cat=[android.intent.category.BROWSABLE] dat=foo://my.test.com (has extras) } from pid 533.

    After that , I’m not able to view the native app and only the error message
    “Webpage not available is being displayed.”. Is there any other things I need to do .Am I missing something. Can anyone provide any solutions for this…..

  6. Leo26781

    Akshata ,

    were you able to pass the values from html page to android application and acces them within the app ? If so can you share it ?

  7. francesco

    Leo,
    maybe too late for your work.
    However try:

    In your webpage:
    Foo? What’s that?

    In your Activity add:

    onCreate(Bundle savedInstanceState) {

    Intent i = getIntent();
    String strdata = i.getDataString();

    strdata will contain foo://my.tost.com?arg1=QwerTy342
    That is you can get what is passed by the webpage.

  8. francesco

    I see that my comment was interpreted as html.
    I meant in the web page try an HREF like the following:
    __HREF=”foo://my.test.com?arg1=QwerTy342″

  9. Ahmed

    Is it possible to pass values from the application back to the calling page?
    Thanks.

  10. I am actually delighted to glance at this weblog posts
    which consists of plenty of valuable facts, thanks for providing these
    data.

  11. Excellent post. I was checking continuously this blog and
    I am inspired! Very useful info specifically the closing section :)
    I handle such info a lot. I used to be seeking this particular
    info for a very lengthy time. Thank you and
    good luck.

Leave a Reply