PhoneGap / Ionic 1
Imal Perera  

Adding Custom URL Schema in Phonegap App

Spread the love

Lets say that you have a web site also a mobile application for the site, and now for a special reason you want to launch the mobile application once user click a link on the website, in this situation you want to pass few parameters to the mobile application as well. custom URL schema is to cater this situation.

I’ll be explaining usage of launchmyapp which is a phonegap plugin allows to create an mobile app that listen to specific url schema and once such a link is clicked the mobile app automatically launch.

First of all we need to add this plugin, so add the following line to your config.xml

 



        



as you can see in the above xml, links that contains “videomobapp” will launch the mobile app once the link is clicked, for example Url like below will launch the app
 

Click here to Open Mobile app

Ok.. now we are almost done, but now we need to extract the parameters that are passing to the mobile app when the user click on it.
 
handleOpenURL(url) is the function that fires when mobile application is launched from the URL. by writing a simple REGEX like below we can extract the parameters


function handleOpenURL(url) {
	var arrparams = url.match("^videomobapp://\\?userid=((.?)*)\\&sesid=((.?)*)$");
	var userid = arrparams[1];
	var sessionid = arrparams[3];
  	console.log("Params" + arrparams);
}

Well that is the end of the post let me know if you find any difficulty in getting this done 🙂

Leave A Comment