title: Device is not defined error pops up when launching my Phonegap Push notification app
body: <p>I used the example source code from (<a href="https://github.com/phonegap-build/PushPlugin/tree/master/Example/www" rel="noreferrer">https://github.com/phonegap-build/PushPlugin/tree/master/Example/www</a>). Problem is that, when I install my app and launch it my android phone (or android SDK emulator), it fails to register device to Android GCM. All the time error pops-up - "Device is not defined". I dont know exactly how I can catch error, why it fails to register device.</p>
  
  <p>Steps that I preformed is: </p>
  
  <ol>
  <li><p>– Created Phonegap project</p></li>
  <li><p>– Installed following 3 plugins  (cordova-plugin-device.git, cordova-plugin-media.git, PushPlugin).</p></li>
  <li>– Registered App in Google Android GCM and retrieved my Goolge cloud API and Project Number</li>
  <li>Locate the PushNotification.js file that was installed into my project-root/plugins folder. This file was copied into my project-root/www folder and referenced from the index.html </li>
  <li>Added  in my index file</li>
  <li>Added  to my  www/config.xml file</li>
  <li>Added JQuery mobile JS + CSS files to my project</li>
  <li>Changed senderID in my HTML code:"1111146417746</li>
  <li>Builded app with CLI - phonegap build android</li>
  </ol>
  
  <p>And here is my Index.html code:</p>
  
  <pre><code>&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;link rel="stylesheet" href="ext/jquery/jquery.mobile-min.css"&gt;
      &lt;script type="text/javascript" src="ext/jquery/jquery-min.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript" src="ext/jquery/jquery.mobile-min.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript" src="ext/jquery.qrcode.js"&gt;&lt;/script&gt;
          &lt;script type="text/javascript" charset="utf-8" src="cordova.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 
                  { 
                      pushNotification = window.plugins.pushNotification;
                $("#app-status-ul").append('&lt;li&gt;registering ' + device.platform + '&lt;/li&gt;');
                      if (device.platform == 'android' || device.platform == 'Android' ||
                              device.platform == 'amazon-fireos' ) {
              pushNotification.register(successHandler, errorHandler, {"senderID":"111111117746","ecb":"onNotification"});        // required!
                      } else {
                          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;');
                       // showing an alert also requires the org.apache.cordova.dialogs plugin
                       navigator.notification.alert(e.alert);
                  }
  
                  if (e.sound) {
                      // playing a sound also requires the org.apache.cordova.media plugin
                      var snd = new Media(e.sound);
                      snd.play();
                  }
  
                  if (e.badge) {
                      pushNotification.setApplicationIconBadgeNumber(successHandler, e.badge);
                  }
              }
  
              // handle GCM notifications for Android
              function onNotification(e) {
                  $("#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;');
  
                                  // on Android soundname is outside the payload. 
                                      // On Amazon FireOS all custom attributes are contained within payload
                                      var soundfile = e.soundname || e.payload.sound;
                                      // if the notification contains a soundname, play it.
                                      // playing a sound also requires the org.apache.cordova.media plugin
                                      var my_media = new Media("/android_asset/www/"+ soundfile);
  
                              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;');
                          //android only
                          $("#app-status-ul").append('&lt;li&gt;MESSAGE -&gt; MSGCNT: ' + e.payload.msgcnt + '&lt;/li&gt;');
                          //amazon-fireos only
                          $("#app-status-ul").append('&lt;li&gt;MESSAGE -&gt; TIMESTAMP: ' + e.payload.timeStamp + '&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>