Testing PhoneGap, Parse, and Push? Read This

This post is more than 2 years old.

Back in October of last year I wrote a guide to integrating PhoneGap, Parse, and push notifications. Recently a reader noticed that my guide no longer worked and asked me to dig into it. I did today and have found the root of the issue.

I began by creating a new PhoneGap 2.5.0 project at the command line and adding in the Android platform. I then followed the directions from my blog post. Since I wasn't testing intents, just notifications, I only followed about half of the guide. Basically the portions where I updated AndroidManifest.xml and the Java source.

I deployed this to my Android device, went to the Parse dashboard, and sent a push. As my reader noted, the push did not show up. I began my investigation by looking at the Data Browser. Part of the Data Browser is a grid of "Installation" objects. These are all the people who have installed your app. It also includes a channels array that signifies what push channels, if any, the device is subscribed to.

Notice that every single device is subscribed to "", which represents the broadcast channel. I.e., everyone should get it. On a whim, I decided to try subscribing to a channel called foo. You can see it in the list above. I did this by simply adding one additional line of Java code:

PushService.subscribe(this, "", testpush2.class);
PushService.subscribe(this, "foo", testpush2.class);

I then went to the Parse dashboard and tweaked "Send to" to specify a segment.

Notice that foo shows up. That's cool. It meant my Java code was definitely working, and Parse recognized that foo was a possible channel. I selected foo, entered some text, hit send, and...

Boom. It worked. WTF, right?

I then wondered - what would have happened if I had selected "Broadcast" in the drop down? I did... and it worked!

From what I can tell, something about Parse's dashboard has changed. The default option to send to everyone wasn't the same as sending to the Broadcast channel, but it was in the past. Here's a visual representation of my tests.

So as far as I know, everything still works just the same as before, it is just the dashboard that has changed in terms of how you test. I'm going to post to Parse's forums about this to see what the specific difference is and if I get an answer, I'll post a link to it in the comments below.

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 Hຜtor Ramos posted on 3/7/2013 at 9:20 PM

The previous version of the push composer defaulted to the Broadcast channel, "". The new Push Console defaults to "Everyone", which would be all Installation objects, regardless of which channels they've been subscribed to.

When you subscribe to push notifications in Android, you specify an Activity which should be launched based on the channel being targeted. From your example:

PushService.subscribe(this, "", testpush2.class);
PushService.subscribe(this, "foo", testpush2.class);

These lines tell Parse to launch testpush2.class when a push notification is sent to either the Broadcast channel, or to the "foo" channel.

Since "Everyone" is not using a channel, there is no Activity associated with it, and you'd see a message indicating so in Logcat.

You can define a default activity to be launched by default whenever if the incoming push notification is not sent to a specific channel, or the channel has no associated activities:

PushService.setDefaultPushCallback(this, testpush3.class);

Now, any push notifications sent to "Everyone", or any channel other than "" or "foo", will be associated with the testpush3.class Activity.

Comment 2 by Raymond Camden posted on 3/7/2013 at 9:22 PM

Dude, awesome, that makes perfect sense. Thank you for responding in all of - what - 5 minutes? :)

Comment 3 by Erich Grüttner posted on 3/7/2013 at 10:49 PM

Thank you again Raymond...now it works like a charm!
Please keep up the good work!!!

Comment 4 by raul posted on 3/8/2013 at 4:59 PM

Still to me does not work,

I'm using eclipse 2.4 cordova

I source code is:

/ / java

com.parse.Parse import;
com.parse.PushService import;

Parse.initialize (this, "code", "code");
PushService.subscribe (this, "prova" AlertesAjuntamentActivity.class);
PushService.setDefaultPushCallback (this, AlertesAjuntamentActivity.class);

/ / manifest

<uses-sdk android:minSdkVersion="10"/>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver">
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</ intent-filter>
</ receiver>

Comment 5 by Raymond Camden posted on 3/8/2013 at 5:16 PM

Can you please describe *how* it isn't working? Is your device being subscribed, ie, you see it in the dashboard?

Comment 6 by Raul posted on 3/8/2013 at 5:36 PM

If you register with parse.com but do not get anything on the phone.

I tried to send it to all the channel i like you suggested in this article, but neither test has worked.

Comment 7 by Raymond Camden posted on 3/8/2013 at 8:03 PM

"If you register with..." - um,did you mean you *did* register?

Can you answer my earlier question - if you see the subscription in the dashboard?

Comment 8 by Raúl posted on 3/9/2013 at 8:36 PM

Yes, I can see the subscription in the dashboard

Comment 9 by Raymond Camden posted on 3/9/2013 at 8:40 PM

Then you got me. If you want to share your code with me, I'll take a look. I'll consider it NDA. Just email it to raymondcamden@gmail dot com.

Comment 10 by biapar posted on 3/14/2013 at 2:49 PM

Which template Do use you for the app?

Comment 11 by Raymond Camden posted on 3/14/2013 at 3:24 PM

What do you mean, biapar?

Comment 12 by demas posted on 5/19/2013 at 11:01 AM

hi ray,
thanks for your tutorial, its working!!
but, how can i send it to specific user?
like uuid or some ID that i created before.
please tell me how

Comment 13 by Raymond Camden posted on 5/19/2013 at 5:00 PM

Yes, see Advanced Targeting: https://parse.com/docs/push...

Comment 14 by demas posted on 5/20/2013 at 8:53 AM

can i setchannel inside phonegap app?

Comment 15 by Raymond Camden posted on 5/20/2013 at 2:35 PM

Um, well, my understanding is that your app sets what it subscribes too. See my earlier post on Parse/Push.

Comment 16 by Nelson posted on 5/28/2013 at 1:18 AM

Hi Ray, I have to record the notification data in sqlite database when the notification arrives, is it possible?

Comment 17 by Raymond Camden posted on 5/28/2013 at 2:48 AM

I believe, stress believe, you can't, until the user takes action on the notification and opens the app. You can handle knowing they did so. But you can't run it when the notification arrives. (My confidence on this is not 100%.)

Comment 18 by Nelson posted on 5/28/2013 at 4:50 AM

Thanks for the reply Ray. I've tried running your example, but when the user takes action on the notification, a black screen appears for a few seconds and the activity is reloaded. Any idea?, this is my code:

<!-- index.html -->
<!doctype html>
<title>Prueba Parse Push</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, width=device-width"/>
<link rel="stylesheet" href="css/jquery.mobile.structure-1.3.1.min.css" />
<link rel="stylesheet" href="css/jquery.mobile-1.3.1.min.css" />
<link rel="stylesheet" href="css/jquery.mobile.theme-1.3.1.min.css" />
<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="js/jquery.mobile-1.3.1.min.js"></script>
<script type="text/javascript" src="js/cordova-2.6.0.js"></script>
<script type="text/javascript" src="js/webintent.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<div data-role="page">
<div data-role="header">
<h1>Prueba Parse Puse</h1>
<div data-role="content">
<div data-role="fieldcontain">
<label for="cajaTexto">Info del Push</label>
<input type="text" name="cajaTexto" id="cajaTexto">
<div data-role="footer">
<h4>Pie del formulario</h4>

// index.js

document.addEventListener("deviceready", dispositivoListo, false);

function dispositivoListo() {
alert("Device Ready");
function(has) {
if(has) {
function(d) {
alert('App invoked from alert with data');
}, function() {
// There was no extra supplied.
alert('No data passed');

Comment 19 by Raymond Camden posted on 7/3/2013 at 6:48 PM

Sorry for the delay in responding. Note - in the future - please do not paste large blocks of code here. Use a pastebin or gist link instead. As I'm almost two months late responding, were you able to get around it?

Comment 20 by Stelios Kouremenos posted on 7/15/2013 at 7:02 PM

Hi Raymond,
I used your code to open my phonegap app (cordova 2.9.0) via a Parse Push notification msg. It works great! However, a new instance of the activity is created each time a Notification is clicked and as a result i get multiple instances opened at the same time. Do u have any idea of how i could kill the running activity so as to have only one activity running?

Comment 21 by Raymond Camden posted on 7/15/2013 at 11:03 PM

So are you saying you would see 2+ instances in the open apps listing?

Comment 22 by Stelios Kouremenos posted on 7/15/2013 at 11:55 PM

Thank u for your question. No. I dont see 2+ instances in the open apps listing. I realised that the problem is that i use 'navigator.app.exitApp()' to close the application. So, i guess exitApp() closes the open windows one by one. I guess this is not the recommended way to close the application. I am using a Lenovo device Android 2.3.