title: phonegap android register for gcm
body: <p>I am new to phonegap and trying to develop an application for android to get it registered with GCM. i have set up the project in google API's. am following the steps in the PushPlugin. i have managed top get the code to run, though i am unable to get the registration id of the device. i am testing on an emulator.</p>
  
  <p>My index.html code:</p>
  
  <pre><code>&lt;!DOCTYPE HTML&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;com.PhoneGap.c2dm&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
  
          &lt;!--&lt;script type="text/javascript" charset="utf-8" src="cordova-2.2.0.js"&gt;&lt;/script&gt;--&gt;
          &lt;script type="text/javascript" charset="utf-8" src="cordova.js"&gt;&lt;/script&gt;
          &lt;script type="text/javascript" charset="utf-8" src="jquery_1.5.2.min.js"&gt;&lt;/script&gt;
          &lt;script type="text/javascript" src="PushNotification.js"&gt;&lt;/script&gt;
  
          &lt;script type="text/javascript"&gt;
              var pushNotification;
  
              function onDeviceReady() {
                  $("#app-status-ul").append('&lt;li&gt;deviceready event received&lt;/li&gt;');
  
                  document.addEventListener("backbutton", function(e)
                  {
                      $("#app-status-ul").append('&lt;li&gt;backbutton event received&lt;/li&gt;');
  
                      if( $("#home").length &gt; 0)
                      {
                          // call this to get a new token each time. don't call it to reuse existing token.
                          //pushNotification.unregister(successHandler, errorHandler);
                          e.preventDefault();
                          navigator.app.exitApp();
                      }
                      else
                      {
                          navigator.app.backHistory();
                      }
                  }, false);
  
                  try 
                  { 
                      console.log("Inside Try-Catch");
                      pushNotification = window.plugins.pushNotification;
                      if (device.platform == 'android' || device.platform == 'Android') {
                          $("#app-status-ul").append('&lt;li&gt;registering android&lt;/li&gt;');
                          pushNotification.register(successHandler, errorHandler, {"senderID":"registration_id","ecb":"onNotificationGCM"});      // required!
                      } else {
                          $("#app-status-ul").append('&lt;li&gt;registering iOS&lt;/li&gt;');
                          pushNotification.register(tokenHandler, errorHandler, {"badge":"true","sound":"true","alert":"true","ecb":"onNotificationAPN"});    // required!
                      }
                  }
                  catch(err) 
                  { 
                      txt="There was an error on this page.\n\n"; 
                      txt+="Error description: " + err.message + "\n\n"; 
                      alert(txt); 
                  } 
              }
  
              // handle APNS notifications for iOS
              function onNotificationAPN(e) {
                  if (e.alert) {
                       $("#app-status-ul").append('&lt;li&gt;push-notification: ' + e.alert + '&lt;/li&gt;');
                       navigator.notification.alert(e.alert);
                  }
  
                  if (e.sound) {
                      var snd = new Media(e.sound);
                      snd.play();
                  }
  
                  if (e.badge) {
                      pushNotification.setApplicationIconBadgeNumber(successHandler, e.badge);
                  }
              }
  
              // handle GCM notifications for Android
              function onNotificationGCM(e) {
                  console.log("Inside onOnNotificationGCM");
                  $("#app-status-ul").append('&lt;li&gt;EVENT -&gt; RECEIVED:' + e.event + '&lt;/li&gt;');
  
                  switch( e.event )
                  {
                      case 'registered':
                      if ( e.regid.length &gt; 0 )
                      {
                          $("#app-status-ul").append('&lt;li&gt;REGISTERED -&gt; REGID:' + e.regid + "&lt;/li&gt;");
                          // Your GCM push server needs to know the regID before it can push to this device
                          // here is where you might want to send it the regID for later use.
                          console.log("regID = " + e.regID);
                      }
                      break;
  
                      case 'message':
                          // if this flag is set, this notification happened while we were in the foreground.
                          // you might want to play a sound to get the user's attention, throw up a dialog, etc.
                          if (e.foreground)
                          {
                              $("#app-status-ul").append('&lt;li&gt;--INLINE NOTIFICATION--' + '&lt;/li&gt;');
  
                              // if the notification contains a soundname, play it.
                              var my_media = new Media("/android_asset/www/"+e.soundname);
                              my_media.play();
                          }
                          else
                          {   // otherwise we were launched because the user touched a notification in the notification tray.
                              if (e.coldstart)
                                  $("#app-status-ul").append('&lt;li&gt;--COLDSTART NOTIFICATION--' + '&lt;/li&gt;');
                              else
                              $("#app-status-ul").append('&lt;li&gt;--BACKGROUND NOTIFICATION--' + '&lt;/li&gt;');
                          }
  
                          $("#app-status-ul").append('&lt;li&gt;MESSAGE -&gt; MSG: ' + e.payload.message + '&lt;/li&gt;');
                          $("#app-status-ul").append('&lt;li&gt;MESSAGE -&gt; MSGCNT: ' + e.payload.msgcnt + '&lt;/li&gt;');
                      break;
  
                      case 'error':
                          $("#app-status-ul").append('&lt;li&gt;ERROR -&gt; MSG:' + e.msg + '&lt;/li&gt;');
                      break;
  
                      default:
                          $("#app-status-ul").append('&lt;li&gt;EVENT -&gt; Unknown, an event was received and we do not know what it is&lt;/li&gt;');
                      break;
                  }
              }
  
              function tokenHandler (result) {
                  $("#app-status-ul").append('&lt;li&gt;token: '+ result +'&lt;/li&gt;');
                  // Your iOS push server needs to know the token before it can push to this device
                  // here is where you might want to send it the token for later use.
              }
  
              function successHandler (result) {
                  $("#app-status-ul").append('&lt;li&gt;success:'+ result +'&lt;/li&gt;');
              }
  
              function errorHandler (error) {
                  $("#app-status-ul").append('&lt;li&gt;error:'+ error +'&lt;/li&gt;');
              }
  
              document.addEventListener('deviceready', onDeviceReady, true);
  
           &lt;/script&gt;
          &lt;div id="home"&gt;
              &lt;div id="app-status-div"&gt;
                  &lt;ul id="app-status-ul"&gt;
                      &lt;li&gt;Cordova PushNotification Plugin Demo&lt;/li&gt;
                  &lt;/ul&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Anything that i am missing or doing wrong?</p>
  
  <p>EDIT: i added a few logs and determined that the onNotificationGCM() method is not getting called after the successHandler() is called</p>