how to send push notification using phonegap and parse
I followed this tutorial which worked very well directly. It also explains how to get the device token.
It is alerted for you to type it over, but you can also hook your phone up to your computer and read the logcat files. (You can use the "monitor" tool in the android SDK)
UPDATE WITH EXAMPLE
Most steps are basically a direct copy of devgirls tutorial I mentioned before
In windows command prompt:
phonegap create quickpush
cd quickpush
phonegap local build android
phonegap local plugin add https://github.com/phonegap-build/PushPlugin
I skipped this, I dont copy the file to the www dir. I just leave it where it is.
add
<script type="text/javascript" src="PushNotification.js"></script>
to index.htmladd
<gap:plugin name="com.phonegap.plugins.pushplugin" />
to config.xml (this is different from site and solves not supported error)-
Copy the push code in the onDeviceReady function in /js/index.js file. Obviously add your own key from google
alert('device ready'); try { var pushNotification = window.plugins.pushNotification; pushNotification.register(app.successHandler, app.errorHandler,{"senderID":"--SENDER ID FROM GOOGLE--","ecb":"app.onNotificationGCM"}); } catch (ex) { alert('error: ' + ex); }
-
Copy the callback handler function in /js/index.js file
successHandler: function(result) { alert('Callback Success! Result = '+result) }, errorHandler:function(error) { alert(error); }, onNotificationGCM: function(e) { switch( e.event ) { case 'registered': if ( e.regid.length > 0 ) { console.log("Regid " + e.regid); alert('registration id = '+e.regid); } break; case 'message': // this is the actual push notification. its format depends on the data model from the push server alert('message = '+e.message+' msgcnt = '+e.msgcnt); break; case 'error': alert('GCM error = '+e.msg); break; default: alert('An unknown GCM event has occurred'); break; } }
build the app:
phonegap remote build android
Struggling Developer
Updated on July 24, 2022Comments
-
Struggling Developer almost 2 years
I am creating an android app using php,jquery and phonegap. I have searched so many things in google but i cant find to send push notification. I have seen this Phonegap and Parse.com Push Notifications IOS But i am not clear ho can i get deviceToken.
I have also seen the below
https://parse.com/questions/php-rest-example-of-targeted-push
I understood how to send notification. But without devicetoken how can i send push notification. Can anybosy tell me how can i get the device token.
-
Struggling Developer over 10 yearsi am following the tutorial on part1>4 step it showing error "error fetching problem make sure it is accessible on your path" could you tell me why it is showing
-
Hugo Delsing over 10 yearsThat seems like half of an error. Something that is similar to that message is when you dont have GIT installed, or dont have GIT added to your path variable. Perhaps blog.countableset.ch/2012/06/07/adding-git-to-windows-7-path
-
Hugo Delsing over 10 yearsyou need it to download the plugin. To locally compile/debug my apps I have installed android SDK, ANT and GIT. Saves a lot of time with publishing and then scanning the QR code :)
-
Struggling Developer over 10 yearsat last i have created a sample app and tried to upload in phonegap but it is hsowing error "plugin unsupported: com.adobe.plugins.pushplugin " @Hugo Delsing could you please tell me why it is showing
-
Hugo Delsing over 10 yearsI honestly have no idea why it would show that. Some guesses: You are using an older version of phonegap. You installed the plugin in another dir on your computer and not included in the project. You need to compile it localy. I'm fairly new at phonegap myself. The tutorial worked for me, but I havent encountered many strange errors yet.
-
Hugo Delsing over 10 yearsJust checked and indeed it builds localy but not remotely. First hit on google with the error solved it: community.phonegap.com/nitobi/topics/…
-
Struggling Developer over 10 yearsHey @Hugo Delsing sorry for asking. Could you give me a sample copy of this app ...
-
Hugo Delsing over 10 yearsI'll see if I can build something tomorrow. Current version contains production code.
-
Hugo Delsing over 10 yearsAdded example to solution
-
SMUsamaShah almost 10 yearsThanks for simplified tutorial
-
Hugo Delsing over 8 yearsThe class not found error seems to be related to wrong config files. See Class not found. On devgirls site, somebody mentioned the same problem and the solution was: 'I know this is a bit late, but I was able to fix the “Class not found” error by rebuilding the app without Hydration from inside of PhoneGap Build.'