Introduction: If you are opening your Android app using custom URL scheme and passing some parameter in the custom URL, then after opening the app you may need to get the parameter. So here is the solution for it.
Description: Suppose you are opening your application from other application e.g. email and you need some parameter like username attached with the url that you have created as custom url.
Launch Application
This is the url which will launch the application from email when you click on the link.
And here is the intent in AndroidManifest.xml which will handle the custom scheme to launch the application.
So in the next step you need a plugin which will interact with the intent created in Manifest and help you to get the custom URL. For this there is a plugin called WebIntent is already available for PhoneGap .
1. Download the WebIntent PhoneGap plugin for Android from here https://github.com/phonegap/phonegap-plugins/tree/master/Android/WebIntent
2. Copy the WebIntent.java file and put it inside the src hierarchy of your project.
3. Change the package name with the package name of your project at the top of the WebIntent.java file. In my case I put it inside src/com/phonegap/demo and renamed the package name in java file from com.borismus.webintent to com.phonegap.demo.webintent.
4. Add the js for phonegap (phonegap/cordova.js) in your html page.
5. Copy the webintent.js file, put it inside the assets/www folder of your project and refer it in header section of your html page.
6. Add the reference for the plugin in res/xml/config.xml file.
7. Now create a function to get the custom URL when app lauches using custom URl.
function GetCustomUrl() { window.plugins.webintent.getUri(function(url) { if(url !== "") { //Here you can parse the url and do anything you want. var link = url.split('='); var username = link[1]; alert(username); } }); }
8. Add the eventlistner to load the function when device gets ready.
document.addEventListener("deviceready", GetCustomUrl, false);
Summary: So using the above example you can get the custom url and the parameter attached with it for Android PhoneGap application.