Ron Piwetz
Ron Piwetz

Reputation: 91

How do I receive notifications with Parse, Phonegap and the phonegap-parse-plugin?

I have spent the last few days trying to get notifications working, reading up on all sorts of plugins and I've come to the end of my rope. I've been able to successfully receive notifications with Parse's test apps on Android and iOS, but whenever I try to add to my own app I see an error in adb logcat

cordova version: 3.5.0-0.2.4

phonegap-parse-plugin

These are the steps I perform:

cordova create pushTest cordova platform add android cordova plugin add https://github.com/benjie/phonegap-parse-plugin

then inside of www/js/index.js I alter the onDeviceReady function to look like this (with my actual appID and clientKey substituted)

onDeviceReady: function() { app.receivedEvent('deviceready'); parsePlugin.initialize(appId, clientKey, function() { parsePlugin.subscribe('', function() { alert('OK'); }, function(e) { alert('error'); }); }, function(e) { alert('error'); }); }

Then I clear out my Installation class in Parse to make sure the app registers successfully. I also make sure any previous app I've installed to my android device has been deleted. Then...

cordova build adb install platforms/android/ant-build/HelloCordova-debug.apk

I get an alert popup that says 'OK' and I have a new record in the Installation class in Parse. I make sure the app is not running in the foreground on my android device. I then send a push notification from Parse, and I don't see anything while running adb logcat From some other debugging I had tried, I tried replacing the version of the Parse SDK from 1.3.8 to 1.5.1 by just removing the old file from the platforms/android/libs dir and putting the new one there. Once I do that, I see the below error in adb logcat

( 2795): GCM message io.cordova.hellocordova 0:1402793727153630%0#39597f64f9fd7ecd W/GCM-DMM ( 2795): broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg=io.cordova.hellocordova (has extras) }

That error is what I've been stuck at, and would love guidance with.

My code (minus my appID and clientKey) is available at: https://github.com/rpiwetz/notif7

Upvotes: 2

Views: 1396

Answers (2)

Pete
Pete

Reputation: 4622

I had very similar problems, the init function worked fine but I wasn't receiving notifications. In the end I manually added some code to the main Activity class:

// register device for parse
Parse.initialize(this, "app_id", "client_key");
PushService.setDefaultPushCallback(this, MyApp.class);
ParseAnalytics.trackAppOpened(getIntent());
ParseInstallation.getCurrentInstallation().saveInBackground();

From: https://stackoverflow.com/a/24426563/884842

Upvotes: 0

Hazem Hagrass
Hazem Hagrass

Reputation: 9808

You may want to check this plugin for sending and receiving notification using parse for android

Upvotes: 1

Related Questions