I'd like to be able to prompt my app to open a link when user clicks on an URL of a given pattern instead of allowing the browser to open it. This could be when the user is on a web page in the browser or in an email client or within a WebView in a freshly-minted app.
For example, click on a YouTube link from anywhere in the phone and you'll be given the chance to open the YouTube app.
How do I achieve this for my own app?
There are some libraries parse parameters from url automatically.
such as
https://github.com/airbnb/DeepLinkDispatch
&&
https://github.com/mzule/ActivityRouter
The later one is wrote by me. Which can parse parameters to given type, not always String.
Example
Use an android.intent.action.VIEW of category android.intent.category.BROWSABLE.
From Romain Guy's Photostream app's AndroidManifest.xml,
Once inside you're in the activity, you need to look for the action, and then do something with the URL you've been handed. The
Intent.getData()
method gives you a Uri.It should be noted, however, that this app is getting a little bit out of date (1.2), so you may find there are better ways of achieving this.