private void _sendResultOfCommand(CallbackContext callbackContext, PluginResult pluginResult) {

    // debugLog("Send result: " + pluginResult.getMessage());
    if (pluginResult.getStatus() != PluginResult.Status.OK.ordinal())
      debugWarn("WARNING: " + PluginResult.StatusMessages[pluginResult.getStatus()]);

    // When calling without a callback from the client side the command can be null.
    if (callbackContext == null) {
      return;
    }

    callbackContext.sendPluginResult(pluginResult);
  }
    void encodeAsMessage(StringBuilder sb) {
      if (pluginResult == null) {
        sb.append('J').append(jsPayloadOrCallbackId);
        return;
      }
      int status = pluginResult.getStatus();
      boolean noResult = status == PluginResult.Status.NO_RESULT.ordinal();
      boolean resultOk = status == PluginResult.Status.OK.ordinal();
      boolean keepCallback = pluginResult.getKeepCallback();

      sb.append((noResult || resultOk) ? 'S' : 'F')
          .append(keepCallback ? '1' : '0')
          .append(status)
          .append(' ')
          .append(jsPayloadOrCallbackId)
          .append(' ');
      switch (pluginResult.getMessageType()) {
        case PluginResult.MESSAGE_TYPE_BOOLEAN:
          sb.append(pluginResult.getMessage().charAt(0)); // t or f.
          break;
        case PluginResult.MESSAGE_TYPE_NULL: // N
          sb.append('N');
          break;
        case PluginResult.MESSAGE_TYPE_NUMBER: // n
          sb.append('n').append(pluginResult.getMessage());
          break;
        case PluginResult.MESSAGE_TYPE_STRING: // s
          sb.append('s');
          sb.append(pluginResult.getStrMessage());
          break;
        case PluginResult.MESSAGE_TYPE_BINARYSTRING: // S
          sb.append('S');
          sb.append(pluginResult.getMessage());
          break;
        case PluginResult.MESSAGE_TYPE_ARRAYBUFFER: // A
          sb.append('A');
          sb.append(pluginResult.getMessage());
          break;
        case PluginResult.MESSAGE_TYPE_JSON:
        default:
          sb.append(pluginResult.getMessage()); // [ or {
      }
    }
 void encodeAsJsMessage(StringBuilder sb) {
   if (pluginResult == null) {
     sb.append(jsPayloadOrCallbackId);
   } else {
     int status = pluginResult.getStatus();
     boolean success =
         (status == PluginResult.Status.OK.ordinal())
             || (status == PluginResult.Status.NO_RESULT.ordinal());
     sb.append("cordova.callbackFromNative('")
         .append(jsPayloadOrCallbackId)
         .append("',")
         .append(success)
         .append(",")
         .append(status)
         .append(",[")
         .append(pluginResult.getMessage())
         .append("],")
         .append(pluginResult.getKeepCallback())
         .append(");");
   }
 }