Twitter: cfjedimaster


Address: Lafayette, LA, USA

Testing PhoneGap, Parse, and Push? Read This

03-07-2013 5,205 views Mobile 15 Comments

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.

Related Blog Entries

15 Comments

  • Commented on 03-07-2013 at 10:20 AM
    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.
  • Commented on 03-07-2013 at 10:22 AM
    Dude, awesome, that makes perfect sense. Thank you for responding in all of - what - 5 minutes? :)
  • Erich Grüttner #
    Commented on 03-07-2013 at 11:49 AM
    Thank you again Raymond...now it works like a charm!
    Please keep up the good work!!!
  • raul #
    Commented on 03-08-2013 at 5:59 AM
    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">
    <intent-filter>
    <action android:name="android.intent.action.BOOT_COMPLETED" />
    <action android:name="android.intent.action.USER_PRESENT" />
    </ intent-filter>
    </ receiver>
  • Commented on 03-08-2013 at 6:16 AM
    Can you please describe *how* it isn't working? Is your device being subscribed, ie, you see it in the dashboard?
  • Raul #
    Commented on 03-08-2013 at 6:36 AM
    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.
  • Commented on 03-08-2013 at 9:03 AM
    "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?
  • Raúl #
    Commented on 03-09-2013 at 9:36 AM
    Yes, I can see the subscription in the dashboard
  • Commented on 03-09-2013 at 9:40 AM
    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.
  • Commented on 03-14-2013 at 5:49 AM
    Which template Do use you for the app?
  • Commented on 03-14-2013 at 6:24 AM
    What do you mean, biapar?
  • Commented on 05-19-2013 at 2: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
  • Commented on 05-19-2013 at 8:00 AM
    Yes, see Advanced Targeting: https://parse.com/docs/push_guide#sending-queries/...
  • Commented on 05-19-2013 at 11:53 PM
    can i setchannel inside phonegap app?
  • Commented on 05-20-2013 at 5:35 AM
    Um, well, my understanding is that your app sets what it subscribes too. See my earlier post on Parse/Push.

Post Reply

Please refrain from posting large blocks of code as a comment. Use Pastebin or Gists instead.

Leave this field empty