javascriptandroidcordovaandroid-intentphonegap

How to handle incoming content with Intent in PhoneGap


I am building a PhoneGap app.

I have successfully added the intent filter to the AndroidManifest.xml and when a link is clicked with specified scheme and host, my app is in the list of application capable of opening the link.

Up to this it is perfect.

Now, when my app is launched, I want to detect which link launched my app.

So, if there are two links:

example.com/temrs

example.com/contact

I want to know which element launched the app, so that I can show related content in the app.

I have tried a number of plug ins but without any success.

Plug in: cordova-plugin-intent

https://github.com/napolitano/cordova-plugin-intent

I have installed this plug-in. My config.xml has this:

<plugin name="com.napolitano.cordova.plugin.intent" spec="https://github.com/napolitano/cordova-plugin-intent" />

In index.html, I have:

<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>

In index.js, I have added this:

document.addEventListener('deviceReady', function(){
    window.plugins.intent.getCordovaIntent(function (Intent) {
        console.log(Intent);
    }, function () {
        console.log('Error');
    });
});

And I am getting this error in console:

Uncaught TypeError: Cannot read property 'getCordovaIntent' of undefined

I am on to this for two days, I really wish someone could give me a solution.


Solution

  • Check out Eddy's cordova-plugin-customurlscheme, it's the defacto plugin for Custom Url Schemes in Cordova:

    <plugin name="cordova-plugin-customurlscheme" />