Test Script

Friday, July 26, 2013

Custom URL Scheme in Android

Hi guys, I am back with yet another simple but interesting Tutorial for you. Today we will be seeing on how to use a Custom URL scheme in Android.

Why do you even need it, you ask?

Well imagine the possibility if you open your app through a simple link on the Internet. I will be considering two case scenarios here to give you a better idea of the concept.

Scenario 1:

So lets say, for some reason you want to be able to open your app whenever the user clicks on Facebook link.

Here is how to do it :

Inside your activity declaration in the Manifest file, add a Intent Filter with the data tag as below :


So now every time the user clicks on a FB Link your app will be shown as a option to open the link.

Simple and pretty neat huh?

Scenario 2:

So your not happy with just opening FB links & want to open  your app based on some of your links probably placed on your website to provide a tight coupled feeling to the user.

Lets do that now :

This is pretty much similar to the previous approach but here we define our own custom scheme. So again inside the Activity tag in your Manifest file add the following :


Now here we see we have defined our own custom scheme, this could be anything you wish to name. So now on your website just add a anchor tag with the link as the Custom Url scheme.

Click to open my app

Thats it, now when the user clicks on that link through his device , your app will be opened automatically.

There is still a small part left to this , that being how to read the parameters sent through the link. I will be leaving that to a part 2 of this tutorial.

So i guess thats it for this tutorial ! Hope you enjoyed reading it.

As always feel free to drop me a comment below.

No comments:

Post a Comment

UA-42774700-1 Twitter Bird Gadget