Example of Intents with PhoneGap

This post is more than 2 years old.

This weekend I was reading an email on my phone when I noticed something odd. The link, to a Wikipedia article, prompted me to ask if I wanted to load it in my browser, or in the Wikipedia app. Knowing that the Wikipedia app was built with PhoneGap, I decided to dig into this and see how it was done.

I did some research and discovered that (as far as I could tell), the Wikipedia app was making use of an Android feature called Intents. From my understanding, Intents are a way for applications to...

  • Broadcast out a general request - ie, "I have an address and I'd love for someone to do something fancy with it!"
  • Listen for general requests - ie, "Dude, I can so do awesome things with maps. If you have an address, let me know, cuz I'll so do something awesome with it. Awesome."

Turns out there is already a plugin for this: WebIntent. To make use of this plugin, you have to modify the Java code a bit (I forgot to bookmark it, but someone else provided the help here) to support the latest version of PhoneGap. I've included a copy with my blog entry so feel free to just copy it from there. But once you have the plugin installed, you can do either (or both) of the actions above.

Creating an intent is as simple as using a bit of JavaScript:

But making your application listen for an intent involves a bit more work, specifically, modifying your AndroidManifest.xml file. You need to add a bit of XML in this to register the intent while also using JavaScript in your application to notice when your app was launched.

Via Stackoverflow, I found this entry on listening out for Youtube links, and then added it to my AndroidManifest.xml:

And then I used a bit of JavaScript to notice the intent.

Simple, right? After installing the application, I whipped up a quick HTML page with two links. One pointing to my blog, another to a random Youtube video.

When I click the Youtube link, I now get this:

and if I select my own application, the JavaScript I wrote notices and responds to the invocation:

Pretty simple! I really barely touched on the power and reach of Intents, and I have no idea if something similar exists for iOS (surely it must), but all in all this is incredibly easy to use with PhoneGap.

Download attached file.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Archived Comments

Comment 1 by Brian Swartzfager posted on 5/2/2012 at 6:34 PM

Intents are an important part of the Android application framework, so the fact that PhoneGap can utilize Intents is pretty cool.

Comment 2 by Simon MacDonald posted on 5/2/2012 at 9:01 PM

Yeah, if you did into the PhoneGap source code you will see that Intents are used for core API calls like Camera.takePicture(), Capture.captureAudio(), Capture.captureImage() and Capture.captureVideo(). As well a number for plugins like the SpeechRecognizer and VideoPlayer also use intents to complete actions on Android.

Comment 3 by Raymond Camden posted on 5/2/2012 at 10:00 PM

Simon, does iOS have something similar?

Comment 4 by Simon MacDonald posted on 5/2/2012 at 10:16 PM

Um, yes and no.

WIth Android you can start an intent which is like when iOS starts another app to handle data. For instance when Dropbox fires off iBooks to handle the ePub file I just downloaded.

But you can also start an intent and wait for a result on Android. This way you can cobble together applications using already existing intents. Much in the same way you can pipe together a number of UNIX commands to make something really powerful.

I can't think of an analogy for that type of behaviour on iOS. As best I know as soon as you start a new app on iOS there is no way to pass the data back to the original app.

Comment 5 by Raymond Camden posted on 5/2/2012 at 10:27 PM

Interesting. Thanks. Can iOS also register to be the receiver of an event? Your example just mentioned broadcasting out an intent. (If I read it right.)

Comment 6 by james posted on 8/8/2012 at 5:07 PM

I dont think this works with the new phongap version. Nothing is happening and I copied everything. The download you provided looks just like my file structure.

Comment 7 by Raymond Camden posted on 8/9/2012 at 10:44 PM

It could be that the plugin has not been updated for recent PG versions. Are you using PG 2.0?

Comment 8 by Mikey Reppy posted on 9/19/2012 at 6:09 AM

I too cannot get it working yet with PG 2.0.0. The example as downloaded using PG 1.6.1 works as supplied, but at least my first attempt with PG 2 is not working. I'm also trying to work it in with gwt-phonegap, but since the 1.6 example works, I'm going to work through it stepwise to see what I can find out.

I see that the intent filter is registered, the youtube link/URL gets intercepted on load and passed into my app, but the url response callback does not fire with the URL the way it does in the 1.6 example.

Comment 9 by Raymond Camden posted on 9/19/2012 at 6:25 AM

I'd get the latest WebIntent from here (https://github.com/phonegap... and see if that helps. Be sure to read his readme.md in case the API changed.

Comment 10 by AliBhai posted on 10/10/2012 at 8:47 PM

does webintent can be used to open local pdf file packaged with android app.

Comment 11 by Mikey Reppy posted on 10/10/2012 at 10:58 PM

Getting back to this, it does work with PhoneGap 2.0. I can post a complete solution but the last most maddening thing is that there needs to be a plugin reference in config.xml (res/xml/config.xml) for the WebIntent class, and without that you get very inscrutable class not found errors.

this stackoverflow page was the clearest answer:

This one is also helpful:

I am now going to move on and see if I can integrate this with gwt-phonegap! :-)

Comment 12 by Raymond Camden posted on 10/10/2012 at 11:04 PM

@Mikey: I'm actually doing a blog post related to this in about 20 minutes. :)

@AliBhai: You don't use an Intent to open a file, rather, you broadcast the desire to open a file and apps that have said they respond to such intents ("I can open PDFs!") will respond.

Comment 13 by ArneO posted on 12/27/2012 at 5:50 PM

What about the send event? Is phonegap able to show the URL from a browser if your app is invoked via the "share"-list (send activity)?

Comment 14 by Luca posted on 1/23/2013 at 2:25 PM

Hi, im using this page to catch the text passed throught an application that call my one.
For example: i open an application that has got the "share" button, i press button and there is my app in the list.
When i click my app, it opens and tell me the EXTRA_TEXT, used to call my app.

I did something like this, but it doesnt work :(

document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
function onDeviceReady() {
console.log("Device Ready");

function(url) {
// url is the value of EXTRA_TEXT
}, function() {
// There was no extra supplied.

Comment 15 by Raymond Camden posted on 1/23/2013 at 8:58 PM

How did it fail?

Comment 16 by Luca posted on 1/23/2013 at 9:25 PM

i putted
alert("nothing"); in the
function() {
// There was no extra supplied.
and it everytime execute that alert, instead of alert(url).

This is in the Manifest:
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:host="www.youtube.com" android:mimeType="text/*" />

Comment 17 by Raymond Camden posted on 1/23/2013 at 9:51 PM

Not sure. I'd try the hasExtra API to see if it has something at all. Maybe try some of the other EXTRAs defined in the code - https://github.com/phonegap....

Comment 18 by Luca posted on 1/24/2013 at 2:02 AM

im sorry but im rly noob with this things!!!
First of all thank you for your help!!!!
I tried this way:

function(url) {
// url is the value of EXTRA_TEXT
}, function() {
// There was no extra supplied.

with all EXTRA_stuff, but it still print "niente".
Thank you!

Comment 19 by Raymond Camden posted on 1/24/2013 at 2:38 AM

I bet I know what it is. Check this blog entry:


and note how I had to 'recognize' the data from Parse's push stuff. Specifically:


Comment 20 by Luca posted on 1/24/2013 at 11:52 PM

Thank you another time.
Based on your suggestion i tried a bit of debug:
private static final String TAG = "ProvaIntent";
Bundle extras = getIntent().getExtras();
if (extras == null) {
Log.d(TAG, "error");
String value1 = extras.getString(Intent.EXTRA_TEXT);
Log.d(TAG, value1);

It works: when i call my program from Youtube Share link, it print the youtube link, when i call it from my computer (Run on Eclipse), it prints "error"!!
But i don't know which is the right string to catch the EXTRA_TEXT.
I tried with "android.intent.extra.TEXT" as seen on the Android Developers Guide, but it doesnt work!
So I have only to understand wich is the right string! :)

Thank you!!!!

Comment 21 by Raymond Camden posted on 1/25/2013 at 2:05 AM

So.... you're good?

Comment 22 by Luca posted on 1/25/2013 at 4:16 AM

Not rally because I catched the link in my MainActivity with Java, but i can't catch it in javascript and webintent!


Comment 23 by Raymond Camden posted on 1/25/2013 at 5:55 PM

Not sure what to suggest then. If you want, you could send me the code and I could try here, but that crosses the line into paid support. ;)

Comment 24 by Luca posted on 1/26/2013 at 5:14 AM

Thank you for your help, but i'm doing it only a diversion!!!!
Thank you, my friend ;)

Comment 25 by Yves posted on 1/28/2013 at 1:39 AM

Unfortunately I can't get it run.
I added the <intent-filter> with an <action> "android.intent.category", <category> "android.intent.category.DEFAULT" and "android.intent.category.BROWSABLE", added the plugin as described but nothing happens if I click on the link or android is just asking for other apps to open with and not my own.

Could it be that the plug-in isn't working with cordova/phonegap 2.2.0?

Or do you know another proper way to handle this?

Comment 26 by Yves posted on 1/28/2013 at 1:42 AM

Sorry the <action> is "android.intent.action.VIEW" not "android.intent.category" as written.

Comment 27 by Raymond Camden posted on 1/28/2013 at 4:39 PM

As far as I know this should work just fine with the latest, but I'll give it another try with 2.3.0 just to be sure.

Comment 28 by Yves posted on 1/30/2013 at 1:55 AM

Now I get it run but just with an fictive intent-scheme like "android-intent" and a link pointing to "href='android-intent://'" with an url like youtube or wikipedia it's bizarrely still not asking for my app.
In general it's good because now I can change from an url to my app but unfortunately the webIntent plug-ins method "getUri(function(url)){}" is not getting fired and the url passed is always "null".
You have any idea?

thanks, regards

Comment 29 by Raymond Camden posted on 1/30/2013 at 8:51 AM

No. As I said, I'm going to set up a new test w/ 2.3.0. I just haven't had time yet.

Comment 30 by Raymond Camden posted on 2/8/2013 at 1:33 AM

So, I can confirm me that URL filtering is no longer working. Not sure why, but looking more.

Comment 31 by Raymond Camden posted on 2/22/2013 at 3:00 AM

I just tried with a virgin 2.4.0 PhoneGap project and it _did_ work ok for me. When I visited a YouTube link (like in my demo above), it asked me if I wanted to use my new app.

Want me to send you a zip of my code?

Comment 32 by Yves posted on 2/25/2013 at 5:27 AM

Thanks Raymond.
It would be nice if you could send me your code. But could you grab the url as well?
Because I could trigger my app by using the intent Filter too.

<data android:scheme="http" android:host="www.domain.com" android:pathPattern=".*" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />

The important point is to add the `android:pathPattern` attribute to open your app by using the _host_ attribute together with the _scheme_ attribute.
That means, you could just use the _scheme_ attribute alone or you have to use all three:
- _scheme_
- _host_
- _path_ or _pathPattern_
Just for somebody who has the same issue.

Now I've the problem that I just get `null` returned as URI. Have you had the same issue?
There are some deprecation warnings in the _WebIntent_ Java class, maybe it could be a problem related to this warnings.

Comment 33 by Raymond Camden posted on 2/25/2013 at 6:40 AM

Shoot, I'm sorry, I didn't test getting the url, just the intent working. Will test in the morning.

Comment 34 by Yves posted on 2/25/2013 at 4:00 PM

Nice, you changed your design. Looks good.
I figured out what the problem was in my case.
It's not because of the cordova version or the webintent plug-in,
but in some kind the "nfc-plugin.js"
(https://github.com/chariots... is somehow interfering with the webintent.js. Unfortunately I need both js files, so I have to figure out what the problem exactly is.

Thanks for your time and help.

Comment 35 by Yves posted on 2/25/2013 at 4:00 PM

Nice, you changed your design. Looks good.
I figured out what the problem was in my case.
It's not because of the cordova version or the webintent plug-in,
but in some kind the "nfc-plugin.js"
(https://github.com/chariots... is somehow interfering with the webintent.js. Unfortunately I need both js files, so I have to figure out what the problem exactly is.

Thanks for your time and help.

Comment 36 by Yves posted on 2/25/2013 at 4:36 PM

Ok, I got it.
Both plugins are using the "cordova.addConstructor()" method.

Comment 37 by Yves posted on 2/25/2013 at 4:58 PM

Sorry, for my comment spamming. That will be the last one.
"In Cordova 2.0 the addConstructor has been removed and checking for Cordova is not necessary.." - Source: http://stackoverflow.com/qu...

Cheers, yves

Comment 38 by Raymond Camden posted on 2/25/2013 at 6:03 PM

Dude, this is not spamming at all. Thank you _so_ much for sharing this. I'd recommend filing a bug report on both plugins.

Comment 39 by Yves posted on 2/28/2013 at 2:39 PM

You're right. I will do that.

Comment 40 by Adam posted on 11/9/2013 at 11:34 PM

That old plugin is deprecated. But here is a link to a new repo that is updated to phonegap 3.x: https://github.com/InQBarna...

Comment 41 by Raymond Camden posted on 11/10/2013 at 1:56 AM

Thanks for sharing that, Adam.

Comment 42 by metamagicson posted on 4/8/2014 at 9:15 PM

Hi Raymond.

Thank you for this explantation. But i wonder how i can catch the Intent if a running application is brought back to front on resume. I use the following listener: document.addEventListener("resume", refreshIntentReq, false); But when i try to catch the intent from within refreshIntentReq, the shared intent is empty.

Comment 43 by Vitaly posted on 6/26/2014 at 6:39 AM

Hello all.
I am Vitaly.

I want to get the file absolute path from email attached file.
I made the phonegap app .
when tap attached file on mail, my app run successfully.
but now, I need to read the file content with my phonegap app.

so I need your help to get file path or how to read the file content?

Thanks so much
Look forward to your hearing.

Comment 44 by Raymond Camden posted on 6/26/2014 at 6:39 PM

Is it passed in the intent? If so - just use the File API.

Comment 45 by Vitaly posted on 6/26/2014 at 6:50 PM

thanks for your reply.
I used this plugin

manifest to assign our app to the file extension, we have in mind:
to our app.

I wrote the basic "ondeviceready" function to see, what is in the intent parameter:

onDeviceReady: function() {
window.plugins.webintent.getUri(function(url) {
if(url !== "" && url.length > 5) {
// url is the url the intent was launched with
contentUri: url,
}, function (data) {
}, function (err) {
alert("error query");

the cordova plugins added were (only the first 2 are important for that):

ralfs-air:enableJS puzzler$ cordova plugin ls

com.borismus.webintent 1.0.0 "WebIntent"
com.phearme.cordovaplugin.ContentProviderPlugin 0.2.6 "ContentProviderPlugin"
de.appplant.cordova.plugin....-composer 0.8.1 "EmailComposer"
org.apache.cordova.console 0.2.8 "Console"
org.apache.cordova.device 0.2.9 "Device"
org.apache.cordova.dialogs 0.2.7 "Notification"
org.apache.cordova.inappbrowser 0.4.0 "InAppBrowser"
org.apache.cordova.splashscreen 0.3.0 "Splashscreen"
org.apache.cordova.statusbar 0.1.3 "StatusBar"

But we get the "content://blabla..." url which I can not work with... lack of brain ;-)


Comment 46 by Raymond Camden posted on 6/26/2014 at 10:20 PM

Ah, well then I think you may be out of luck.

Comment 47 by Vitaly posted on 6/26/2014 at 10:40 PM

I can get "content://com.android.email.attachmentprovider/1/32/RAW"
instead of:

so I don't have any idea to read this.

I need your help for this.

Look forward to your hearing.

Comment 48 by Vitaly posted on 6/26/2014 at 10:42 PM

and I get some article from there.

unfortunately, this is not phonegap, so I also stopped to work.


Comment 49 by Raymond Camden posted on 6/26/2014 at 10:44 PM

I don't know - I'd recommend asking on the Google group for PhoneGap. I'm pretty busy at the moment so I can't help you with this.

Comment 50 by Vitaly posted on 6/26/2014 at 10:49 PM

I mean I need your help if you have time.

yeah, sure I will ask on the google group.

Comment 51 by Aswathi posted on 8/18/2014 at 3:36 PM


Now iam developing a phonegap appliaction which download some files from server. after download i want to open file with default application viewer in phone. I have downloaded all files and put it to a folder. But could not open file from my folder. I have to open different format files such as doc/xls/pdf/image etc. Could you please do help.


Comment 52 by Raymond Camden posted on 8/18/2014 at 3:48 PM

What did you try? After the download I mean - what did you try to open the file?

Comment 53 by Aswathi posted on 8/18/2014 at 3:58 PM

I have tried to open that file using

action: WebIntent.ACTION_VIEW,
url:file:///sdcard/MyApp/pdffile.pdf },
function() {},
function(e) {alert('Failed to open URL via Android Intent');}
also tried fileopener,


Comment 54 by Raymond Camden posted on 8/18/2014 at 4:03 PM

And did you see anything in the console when you tried this?

As a general FYI, in order for me to help someone, I need to know what you tried and what was reported when you did. Using remote debugging should tell you if some error was thrown.

Comment 55 by Aswathi posted on 8/18/2014 at 4:16 PM

I have started my phonegap application 1 month back. I did not try remote debugging yet. Now iam Building APK from adobe site(https://build.phonegap.com/) by uploading Zip file not by eclipse and ADT. The issue is with i could not open the file that i have downloaded with polaris viewer or any other default application based on file format.

Comment 56 by Raymond Camden posted on 8/18/2014 at 4:37 PM

Please test with remote debugging. If you view this site's About section you will see a list of articles I've written. There are a few articles there on that topic.

Comment 57 by Aswathi posted on 8/18/2014 at 4:47 PM

Thanks for your valuable time. I will check with remote debugging.

Comment 58 by Aswathi posted on 8/19/2014 at 11:52 AM

hi, my application need some modification now, need to open file inside application . do you have any idea to open files inside application. Is there any API for this. Please do help.


Comment 59 by Raymond Camden posted on 8/20/2014 at 4:44 AM

I'd try window.location = the path. To see if that forces it to try to open.

Comment 60 by Aswathi posted on 8/20/2014 at 8:08 AM

That will open only image/pdf files. I want to view doc/xls file format also. Just like email client attachment.

Comment 61 by Raymond Camden posted on 8/20/2014 at 3:12 PM

Then you got me there. Not sure.

Comment 62 by sergey m posted on 11/9/2014 at 7:41 AM


Is it usable for WebIntent to make app phone calling strightforward? Thanks

Comment 63 by Raymond Camden posted on 11/10/2014 at 12:27 AM


Comment 64 by Peter Frazier posted on 1/18/2015 at 4:08 PM

thank you so much. i started looking at cordova/phonegap yesterday and got all excited but hit a wall 30 min in on how to pull in shared info into my app. I am surprised how this isn't step 2 in any of the doc's. i've been searching for the better part of 10 hours trying to find a tutorial like yours. I was about to give up and just go with copy/paste and shelve it until after..

Comment 65 (In reply to #64) by Raymond Camden posted on 1/18/2015 at 4:15 PM

I'm glad this almost 3 year old post is helpful. :)

Comment 66 (In reply to #0) by Raymond Camden posted on 3/26/2015 at 6:56 PM

Not really. If the web page was changed because of something happening on the server (imagine a web socket connection for ex), then the same thing on the server that triggered the web page change could *also* do a push notification.

Or heck - use web sockets. Looks to be supported well: http://caniuse.com/#feat=we...

Comment 67 by Majid posted on 8/20/2015 at 9:04 AM

First, very thanks for your good tutorial
now i want to ask, can i have this application source code?
attached files in that tutorial doesn't exist!

Comment 68 (In reply to #67) by Raymond Camden posted on 8/20/2015 at 2:00 PM


Comment 69 by Steve Daily posted on 12/7/2015 at 8:23 PM

Thanks very much for the helpful tutorial. I am using PhoneGap Build and have tried a couple different WebIntent plugins, including Tunts' and InQBarna's. When I click on a link such as "www.youtube.com" I see my app listed as an option, but selecting it causes my app to immediately crash, with nothing written to the console, so remote debugging this is very hard. I am wondering if the problem might be this part of my config.xml:

activity android:name="SomeString".

I cannot figure out what is supposed to be in that name field. When I insert my app's actual name from the config.xml name field, the PhoneGap build fails. So I am just inserting an arbitrary string, which allows the build to proceed, but perhaps is leading to these crashes. Any advice would be greatly appreciated.

Comment 70 (In reply to #69) by Raymond Camden posted on 12/7/2015 at 8:31 PM

Sorry - you got me there. I'd try *outside* of PGBuild first.

Comment 71 by Kevin Reynolds posted on 1/27/2016 at 2:46 AM

Great tutorial. Wondering whether you have a working link to the test project you have written.

Comment 72 (In reply to #71) by Raymond Camden posted on 1/27/2016 at 11:58 AM

You can now find it at: http://static.raymondcamden...

Comment 73 by Emre Celik posted on 10/24/2016 at 8:43 AM

I can't get it work for skype for business uri. How can i use for ms-sfb://start ?

Comment 74 (In reply to #73) by Raymond Camden posted on 10/24/2016 at 1:53 PM

If you are using the proper intent, than I'm not sure what to suggest outside of contacting the owner of the plugin.

Comment 75 by Manul King posted on 11/6/2017 at 4:08 PM

Can you redo the zip file link it is broken

Comment 76 (In reply to #75) by Manul King posted on 11/6/2017 at 4:10 PM

Soorry did not read down far enough I found it thanks.

Comment 77 by MAnuel King posted on 11/9/2017 at 2:16 PM

When I add the <application> tag above to the config.xml file then attemp to generate a phonegap build the application tag cause a build error. Is there a work around?

Comment 78 (In reply to #77) by Raymond Camden posted on 11/10/2017 at 2:01 PM

Um - not sure. I'd check with the PG Build docs - support - etc. I haven't used PGB in years.

Comment 79 by Abhilash Raj R.S posted on 5/16/2018 at 7:03 PM

How can i use this tutorial with phonegap desktop build.

Comment 80 (In reply to #79) by Raymond Camden posted on 5/16/2018 at 7:04 PM

No idea on that one. Last time I checked I didn't think it supported plugins well.

Comment 81 (In reply to #80) by Abhilash Raj R.S posted on 5/16/2018 at 7:11 PM

wht the other option i can add Intent to my application

Comment 82 (In reply to #81) by Raymond Camden posted on 5/16/2018 at 7:12 PM

I'd use the command line.

Comment 83 (In reply to #82) by Abhilash Raj R.S posted on 5/16/2018 at 7:16 PM

can u suggest a tutorial so i can study the command line usage

Comment 84 (In reply to #83) by Raymond Camden posted on 5/16/2018 at 7:17 PM

I'd start here: http://cordova.apache.org/d...

I have a book you can buy too (grin), but it is a few years old.

Comment 85 (In reply to #84) by Abhilash Raj R.S posted on 5/16/2018 at 8:10 PM

can i import the current PGB project to CLI

Comment 86 (In reply to #85) by Raymond Camden posted on 5/16/2018 at 8:13 PM

Um - I don't believe so.

Comment 87 (In reply to #86) by Abhilash Raj R.S posted on 5/17/2018 at 5:51 AM

also send link to your book

Comment 88 (In reply to #87) by Raymond Camden posted on 5/17/2018 at 11:05 AM
Comment 89 by Abhilash Raj R.S posted on 5/18/2018 at 11:46 PM

is this i have to add on the config.xml
<plugin name="com.qdev.webintent" spec="https://github.com/okwei200..."/>

Comment 90 (In reply to #89) by Raymond Camden posted on 5/19/2018 at 12:51 PM

I honestly don't remember - this post is six years old. :) I can say plugins should be adding their own strings to config.xml as far as I know.