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.

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

Recaptcha is required.

Sending message..