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.
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.html
add <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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With