The BROWSABLE category revealed

Mattias Rosberg

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?

Mattias Rosberg
Consultant at Jayway

Tags:

2 comments ↓

#1 Samuh Varta on 12.19.09 at 20:10

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 on 05.12.10 at 15:31

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

Leave a Comment