Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to implement push notifications in phonegap application.

    • 0
    • 0
    • 0
    • 0
    • 2
    • 0
    • 0
    • 0
    • 722
    Comment on it

    Using Google Cloud Messaging (GCM) we can send push notification from web server to the android devices that are registered.

    This is how the process works:
    1.Android device sends sender id to GCM server for registration.
    2.GCM Server returns registration id to android device after successful registration.
    3.Android device sends registration id to web server.
    4.GCM registration id is stored in the database at server.
    5.We can get registration id from database whenever push notification is required.
    6.GCM sends push notification after getting request.


    Steps to follow for push notifications:
    1. We have to Register with Google Cloud Messaging from Google developer Console and it provides Sender ID and API key for GCM.

    Registering with Google Cloud Messaging:

    • Go to the link Google APIs Console page and create a new project.
    • Now the project id is generated after creating the project. You can see the project id in the url. The project id will be used as a SENDER ID in android application.
    • After this turn on the Google Cloud Messaging for Android.
    • Now, click on API Manager and create the API Key for your project. This API key will be used when sending requests to GCM server.


    2. Then configure your app to use push notification plugin
    Install the PushPlugin from github by following command:

    $ phonegap local plugin add https://github.com/phonegap-build/PushPlugin 
    

    Add the following script line to your main html file to PushNotification.js.

    <script type="text/javascript" src="PushNotification.js"></script>
    


    1. Register the application with the Google Cloud Messaging service add the following code to get a reference to the push notification plugin object and call the register function.

    var pushNotification = window.plugins.pushNotification;

    pushNotification.register(app.successHandler, app.errorHandler, {"senderID":"824841663931","ecb":"app.onNotificationGCM"});

        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':
                          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;
                    }
                }
    

 2 Comment(s)

  • Hello, I want to introduce a push notification service which supports Chrome and Firefox Browsers in both Mobile and Desktop, called Pushify.

    Pushify offers you Unlimited Free Browser Push Notifications to Unlimited Subscribers by which you can connect with your customers easily even customer not in your website. Notifications will deliver to your Customers Mobile and Desktop. We are offering Unlimited REST API calls, Geo-Targeting, Scheduled Notifications, Free Plugins to CMS & e-commerce, RSS2Push and many features for free. To know more just visit www.pushify.com

  • Hello, I want to introduce a push notification service which supports Chrome and Firefox Browsers in both Mobile and Desktop, called Pushify.

    Pushify offers you Unlimited Free Browser Push Notifications to Unlimited Subscribers by which you can connect with your customers easily even customer not in your website. Notifications will deliver to your Customers Mobile and Desktop. We are offering Unlimited REST API calls, Geo-Targeting, Scheduled Notifications, Free Plugins to CMS & e-commerce, RSS2Push and many features for free. To know more just visit www.pushify.com

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: