Open Application via URL Scheme in Cordova
Posted By : Akhil Dhiman | 02-Jun-2015
Here I will show you how to open application using url schema from any link that comes in mail or text message. For this we need to install cordova plugin name "Custom-URL-scheme". You can check this plugin from below link.
To install this plugin you need to follow below instructions:
cordova plugin add https://github.com/EddyVerbruggen/LaunchMyApp-PhoneGap-Plugin.git --variable URL_SCHEME=mycoolapp
Where mycoolapp is the url schema for your app
Below are the methods to detect whether application is opened from url schema or not
For Android
window.plugins.webintent.getUri(function(url) { alert(url); });
For iOS
var urlToHit = ""; function handleOpenURL(url) { setTimeout(function() { urlToHit = url; alert(urlToHit); }, 500); }
This function have to be in timeout. It will automatically call when device ready event calls.
If you receive any url then you can get your data present in query string and you can do your code.
If you receive any url then you can get your data present in query string and you can do your code.
Server Side code to open app via Intent
In your HTML page add the below script in between script tags
if(navigator.userAgent.toLowerCase().indexOf("iphone") != -1){ window.location = "mycoolapp://view?id=123"; setTimeout(function() { if (!document.webkitHidden) { window.location = 'https://itunes.apple.com/us/app/appdator/"Application_id"'; } }, 25); }else{ window.location = 'intent://view?id=123#Intent;package=com.akhil.test;scheme=mycoolapp;launchFlags=268435456;end;'; }
where view?id=123 is the data received from url scheme
THANKS
Request for Proposal
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Akhil Dhiman
Akhil is an iPhone and Android application developer with experience in PhoneGap and Swift(Native iOS). Akhil has good experience working with JavaScript, jQuery and Underscore as well.