private void showNotificationIfPossible(Context context, Bundle extras) {

    // Send a notification if there is a message or title, otherwise just send data
    Log.d(LOG_TAG, "extra =" + extras.toString());
    String message = extras.getString(MESSAGE);
    String title = extras.getString(TITLE);
    String contentAvailable = extras.getString(CONTENT_AVAILABLE);
    int badgeCount = extractBadgeCount(extras);
    if (badgeCount >= 0) {
      Log.d(LOG_TAG, "count =[" + badgeCount + "]");
      PushPlugin.setApplicationIconBadgeNumber(context, badgeCount);
    }

    Log.d(LOG_TAG, "message =[" + message + "]");
    Log.d(LOG_TAG, "title =[" + title + "]");
    Log.d(LOG_TAG, "contentAvailable =[" + contentAvailable + "]");

    if ((message != null && message.length() != 0) || (title != null && title.length() != 0)) {

      Log.d(LOG_TAG, "create notification");

      if (title == null || title.isEmpty()) {
        extras.putString(TITLE, getAppName(this));
      }

      createNotification(context, extras);
    }

    if ("1".equals(contentAvailable)) {
      Log.d(LOG_TAG, "send notification event");
      PushPlugin.sendExtras(extras);
    }
  }
 @Override
 public void onError(Context context, String errorId) {
   Log.e(LOG_TAG, "onError - errorId: " + errorId);
   // if we are in the foreground, just send the error
   if (PushPlugin.isInForeground()) {
     PushPlugin.sendError(errorId);
   }
 }
  @Override
  protected void onMessage(Context context, Intent intent) {
    Log.d(LOG_TAG, "onMessage - context: " + context);

    // Extract the payload from the message
    Bundle extras = intent.getExtras();
    if (extras != null) {
      // if we are in the foreground, just surface the payload, else post it to the statusbar
      if (PushPlugin.isInForeground()) {
        extras.putBoolean(FOREGROUND, true);
        PushPlugin.sendExtras(extras);
      } else {
        extras.putBoolean(FOREGROUND, false);

        // Send a notification if there is a message
        String message = this.getMessageText(extras);
        String title = getString(extras, TITLE, "");
        if ((message != null && message.length() != 0) || (title != null && title.length() != 0)) {
          createNotification(context, extras);
        }
      }
    }
  }
  @Override
  public void onRegistered(Context context, String regId) {

    Log.v(LOG_TAG, "onRegistered: " + regId);

    try {
      JSONObject json = new JSONObject().put(REGISTRATION_ID, regId);

      Log.v(LOG_TAG, "onRegistered: " + json.toString());

      PushPlugin.sendEvent(json);
    } catch (JSONException e) {
      // No message to the user is sent, JSON failed
      Log.e(LOG_TAG, "onRegistered: JSON exception");
    }
  }
  @Override
  public void onMessageReceived(String from, Bundle extras) {
    Log.d(LOG_TAG, "onMessage - from: " + from);

    if (extras != null) {
      Context applicationContext = getApplicationContext();

      SharedPreferences prefs =
          applicationContext.getSharedPreferences(
              PushPlugin.COM_ADOBE_PHONEGAP_PUSH, Context.MODE_PRIVATE);
      boolean forceShow = prefs.getBoolean(FORCE_SHOW, false);
      boolean clearBadge = prefs.getBoolean(CLEAR_BADGE, false);

      extras = normalizeExtras(applicationContext, extras);

      if (clearBadge) {
        PushPlugin.setApplicationIconBadgeNumber(getApplicationContext(), 0);
      }

      /*
       * do push echo
       */
      Log.d(LOG_TAG, "extras:" + extras);
      PushPlugin.doPushEcho(getBaseContext(), null);

      // if we are in the foreground and forceShow is `false` only send data
      if (!forceShow && PushPlugin.isInForeground()) {
        Log.d(LOG_TAG, "foreground");
        extras.putBoolean(FOREGROUND, true);
        extras.putBoolean(COLDSTART, false);
        PushPlugin.sendExtras(extras);
      }
      // if we are in the foreground and forceShow is `true`, force show the notification if the
      // data has at least a message or title
      else if (forceShow && PushPlugin.isInForeground()) {
        Log.d(LOG_TAG, "foreground force");
        extras.putBoolean(FOREGROUND, true);
        extras.putBoolean(COLDSTART, false);

        showNotificationIfPossible(applicationContext, extras);
      }
      // if we are not in the foreground always send notification if the data has at least a message
      // or title
      else {
        Log.d(LOG_TAG, "background");
        extras.putBoolean(FOREGROUND, false);
        extras.putBoolean(COLDSTART, PushPlugin.isActive());

        showNotificationIfPossible(applicationContext, extras);
      }
    }
  }