Preparing to Develop with Push Notifications (Android)
Prerequisites: Make sure you’ve got the latest version of Eclipse and the Android SDK installed
Starting your PhoneGap project:
Download PhoneGap from http://phonegap.com/download
Create a new Eclipse Android project, copy and paste the contents of phonegap\lib\android\example\ into your project.
Now is a good time to compile and run on your emulator to make sure everything is working.
Adding Push Notifications to your Project
Add PushNotification.js and app.js to your assets/www and link them in your HTML
Add the cordova-push-notifications.jar library to your project and make the following changes to your manifest file: permissions, receiver, etc
Registration of Device
When your application launches, you need to register with the Google GCM server. Do this by running window.plugins.pushNotifications.registerC2DM() inside of a $(document).bind(“deviceready”). This will tell the native code to register the device with the GCM Push Service and get a push token. The token is then handed back to you via the success callback. You will need to send this token to your provider, such as Urban Airship.
An aside note about Urban Airship and urbanairship.js.
Receiving a Push
Somewhere in your code, bind to the following two events to respond to a push.
When a push arrives and the application is not open, it gets queued. When the user taps on the notification from the notifications bar, it will open the application and then fire the outOfAppPushReceived event. This is how to make your application respond to a user tapping on a notification. If your application is open and in the foreground, then it will fire the inAppPushReceived event. At this point, it is up to you to decide what to do (change your page, display something, start an ajax call to fetch data, etc.)
Customizing the Android Notification
If you want to customize the icon or body of the push notification, you need to modify the CreateNotification method in xxx.java.