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 --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) {

For iOS

 var urlToHit = "";
function handleOpenURL(url) {
    setTimeout(function() {
       urlToHit = url;
   	}, 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 = '"Application_id"';
    }, 25);
	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

About Author

Author Image
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.

Request for Proposal

Name is required

Comment is required

Sending message..