What is needed is an intent-filter
for your View action that you'd link to a url scheme.
In your Manifest XML file... The View intent represents the action while the BROWSABLE category responds to web URIs.
Defining the scheme
<activity android:name=".MainActivity>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http"
android:host="your-website.com"
android:path="/somepage/" />
</intent-filter>
</activity>
However, the user must have your app already installed or else s/he will get an error message in the browser. You would abslutely need a fallback. One way to deal with the error problem is to use some Javascript check to verify if user has the app installed (if you are using a Javascript like AngularJS you can bind it to an onclick. If not you can use a redirect of some kind with Javascript or without). If the app is not installed, the user goes to the regular website url. Else, s/he jumps to app.
Handling redirections for users who do not have the app installed
In your website file or in your template file, use Javascript
<script>
//any conditional logic
if( navigator.userAgent.match(/android/i) ) {
// redirect to App
} else {
// stay/redirect to website or something like getting them to install the app
}
</script>
Now when the user clicks on <a href="http://yourweb.com/somepage/">Your Text </a>
, s/he gets to the app but if the app is not installed s/he gets to the page on the browser or the Play Store (see notes below).
Other options
There is another way of doing all of the above. Instead of defing an http scheme, you could have your own custom URI.
<intent-filter>
<data android:scheme="your-custom-URI" />
</intent-filter>
and in your web template file within some sort of conditionals for the redirection fallback...
<a href="your-custom-URI://somepage">Your Text</a>
Extra Notes
Something that would need your attention concerns some browser specifics. Here is how Google Chrome treats the subject.
If have your app on the Play Store you can refer the user to market://details?id=com.your.app.package
to download it.
You can achieve more than that with some Javascript library such as
AngularJS, Vue, etc in your website.