title: how to statusbar notification using phone gap push plugin
body: <p>i used phone gap push plugin it works fine for me, as well as getting msg from my server.
  i have two problems that i want if some one can updated code or where piece of code need to change requirments must be appreciated.</p>
  
  <p>i followed this link showing notification when app is in background u can see it .</p>
  
  <p><a href="http://devgirl.org/2012/10/25/tutorial-android-push-notifications-with-phonegap/" rel="nofollow">http://devgirl.org/2012/10/25/tutorial-android-push-notifications-with-phonegap/</a></p>
  
  <p>Regardinf this document i recieved put but two things not doind as i mention in my two problems.</p>
  
  <ol>
  <li><p>i am showing message count undefined when msg recieved.</p></li>
  <li><p>i want that if my app is running in background so status bar come up like other app that for notification.</p></li>
  </ol>
  
  <p><strong>index.html</strong></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;script type="text/javascript" charset="utf-8" src="cordova-2.2.0.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" charset="utf-8" src="js/main.js"&gt;&lt;/script&gt;
          &lt;script type="text/javascript" charset="utf-8" src="js/service.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;');
  
  
                  try 
                  { 
                      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":"XXXXXXX","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) {
                  $("#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.
  
  
  
                      }
                      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;button id="sendRegistrationID"&gt;Save Registration ID&lt;/button&gt;
                  &lt;button id="getRegistrationID"&gt;Get Registration ID&lt;/button&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>GCMINtentService.js</strong></p>
  
  <pre><code>package com.plugin.gcm;
  
  import java.util.List;
  
  import com.google.android.gcm.GCMBaseIntentService;
  import org.json.JSONException;
  import org.json.JSONObject;
  
  import android.annotation.SuppressLint;
  import android.app.ActivityManager;
  import android.app.ActivityManager.RunningTaskInfo;
  import android.app.Notification;
  import android.app.NotificationManager;
  import android.app.PendingIntent;
  import android.content.Context;
  import android.content.Intent;
  import android.os.Bundle;
  import android.support.v4.app.NotificationCompat;
  import android.util.Log;
  
  @SuppressLint("NewApi")
  public class GCMIntentService extends GCMBaseIntentService {
  
      public static final int NOTIFICATION_ID = 237;
      private static final String TAG = "GCMIntentService";
  
      public GCMIntentService() {
          super("GCMIntentService");
      }
  
      @Override
      public void onRegistered(Context context, String regId) {
  
          Log.v(TAG, "onRegistered: "+ regId);
  
          JSONObject json;
  
          try
          {
              json = new JSONObject().put("event", "registered");
              json.put("regid", regId);
  
              Log.v(TAG, "onRegistered: " + json.toString());
  
              // Send this JSON data to the JavaScript application above EVENT should be set to the msg type
              // In this case this is the registration ID
              PushPlugin.sendJavascript( json );
  
          }
          catch( JSONException e)
          {
              // No message to the user is sent, JSON failed
              Log.e(TAG, "onRegistered: JSON exception");
          }
      }
  
      @Override
      public void onUnregistered(Context context, String regId) {
          Log.d(TAG, "onUnregistered - regId: " + regId);
      }
  
      @SuppressWarnings("deprecation")
      @Override
      protected void onMessage(Context context, Intent intent) {
          Log.d(TAG, "onMessage - context: " + context);
  
  
  
          // Extract the payload from the message
          Bundle extras = intent.getExtras();
          if (extras != null)
          {
              PushPlugin.sendExtras(extras);
  
              // Send a notification if there is a message and not in foreground
              if (!PushPlugin.isInForeground() &amp;&amp; extras.getString("message").length() != 0) {
                  createNotification(context, extras);
              }
          }
      }
  
      public void createNotification(Context context, Bundle extras)
      {
          NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
          String appName = getAppName(this);
  
          Intent notificationIntent = new Intent(this, PushHandlerActivity.class);
          notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
          notificationIntent.putExtra("pushBundle", extras);
  
          PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
  
          NotificationCompat.Builder mBuilder =
              new NotificationCompat.Builder(context)
                  .setDefaults(Notification.DEFAULT_ALL)
                  .setSmallIcon(context.getApplicationInfo().icon)
                  .setWhen(System.currentTimeMillis())
                  .setContentTitle(extras.getString("title"))
                  .setTicker(extras.getString("title"))
                  .setContentIntent(contentIntent);
  
          String message = extras.getString("message");
          if (message != null) {
              mBuilder.setContentText(message);
          } else {
              mBuilder.setContentText("&lt;missing message content&gt;");
          }
  
          String msgcnt = extras.getString("msgcnt");
          if (msgcnt != null) {
              mBuilder.setNumber(Integer.parseInt(msgcnt));
          }
  
          mNotificationManager.notify((String) appName, NOTIFICATION_ID, mBuilder.build());
      }
  
      public static void cancelNotification(Context context)
      {
          NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
          mNotificationManager.cancel((String)getAppName(context), NOTIFICATION_ID);  
      }
  
      private static String getAppName(Context context)
      {
          CharSequence appName = 
                  context
                      .getPackageManager()
                      .getApplicationLabel(context.getApplicationInfo());
  
          return (String)appName;
      }
  
      @Override
      public void onError(Context context, String errorId) {
          Log.e(TAG, "onError - errorId: " + errorId);
      }
  
  }
  </code></pre>