Sometime we a have a situation in which we use android app in our web application.In that situation you can use this.
For opening the android app first we have to check 2 conditions .
1. If the device is android or not.
2. In the android device if the app is installed or not.
1. If the device is android or not- If device is not android then we do not perform that functionality. In that case you can either disable the button or hide the button by using this:
$(document).ready(function () {
var isMobile = {
Android: function () {
return navigator.userAgent.match(/Android/i);
},
any: function () {
return (isMobile.Android());
}
};
if (isMobile.Android()) {
$("[id$btnOpenapp]").show(); //show the button
}
else
{
$("[id$btnOpenapp]").hide(); //hide the button
}
});
2.If the app is installed or not-If app is installed in device then open the app otherwise redirect it app url.For this we set fall back url , if app is not installed then this fall back link will redirect it to app store.
We can do this by:
S.browser_fallback_url=https%3A%2F%2Fwww.google.co.in; // this is an example if app not installed then redirect to google.
In this we give encoded url to set fallback url. This check when we hit url to open the app.
When the conditions check then we have to open the app. We do this thing by doing this:
<input type="button" value="Open App" id="btnOpenapp" visible="true" onClick="location.href ='intent://?ret=ReturnURLPath?QueryStringParameter=#Intent;scheme=schemename;package=PackageName;S.browser_fallback_url=https%3A%2F%2Fwww.google.co.in;end'" />"
In this,
1. ReturnURLPath is the url in which you want the app return after completing task . for eg: we hit the url from myapplication.com so we set ret=myapplication.com
2. QueryStringParameter is the parameter of query string which have value when app return back to web page.After completing the task successfully, app returns to the "ret" URL (or it's default URL) with the Querystring concatenated to it, making the code available to the web via the GET parameters.
for eg:
<input type="button" value="Open App" id="btnOpenapp" visible="true" onClick="location.href ='intent://?ret=myapplication.com?AppData=#Intent;scheme=schemename;package=PackageName;S.browser_fallback_url=https%3A%2F%2Fwww.google.co.in;end'" />
The resulting URL for our previous example would be: http://myapplication.com?AppData={CODE}. Now you can get the value from query string
3. PackageName is the name of package of android app.
4. S.browser_fallback_url is the fall back url if app not installed then open these url.
for any other help you can also refer Help Link
4 Comment(s)