@Override
  public boolean execute(String action, JSONArray args, final CallbackContext callbackContext)
      throws JSONException {

    if (action.equals(ACTION_HAS_SMS_POSSIBILITY)) {

      Activity ctx = this.cordova.getActivity();
      if (ctx.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, true));
      } else {
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, false));
      }
      return true;
    } else if (action.equals(ACTION_SEND_SMS)) {
      try {
        String phoneNumber = args.getString(0);
        String message = args.getString(1);
        this.sendSMS(phoneNumber, message);

        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK));
      } catch (JSONException ex) {
        callbackContext.sendPluginResult(
            new PluginResult(PluginResult.Status.ERROR, ex.getMessage()));
      }
      return true;
    }
    return false;
  }
  public void getDeviceDetail(JSONArray array, CallbackContext callbackContext)
      throws JSONException {
    JSONObject deviceDetail = new JSONObject();

    NetmeraDeviceDetail netmeraDeviceDetail;
    try {
      netmeraDeviceDetail = NetmeraPushService.getDeviceDetail(Netmera.getContext());
    } catch (NetmeraException e) {
      callbackContext.error(jsonError(e));
      return;
    }
    List<String> deviceGroups = netmeraDeviceDetail.getDeviceGroups();

    if (deviceGroups.size() > 0) {
      JSONArray tagArray = new JSONArray();
      for (int i = 0; i < deviceGroups.size(); i++) {
        tagArray.put(deviceGroups.get(i));
      }
      deviceDetail.put("tags", tagArray);
    }

    NetmeraGeoLocation deviceLocation = netmeraDeviceDetail.getDeviceLocation();
    if (deviceLocation != null) {
      JSONObject location = new JSONObject();
      location.put("latitude", deviceLocation.getLatitude());
      location.put("longitude", deviceLocation.getLongitude());
      deviceDetail.put("location", location);
    }

    callbackContext.success(deviceDetail);
  }
  private void doOnUnregistered(String registrationId) {
    CallbackContext callback = callbackIds.get("unregisterDevice");
    if (callback == null) return;

    callback.success(registrationId);
    callbackIds.remove("unregisterDevice");
  }
 private void echo(String message, CallbackContext callbackContext) {
   if (message != null && message.length() > 0) {
     callbackContext.success(message);
   } else {
     callbackContext.error("Expected one non-empty string argument.");
   }
 }
  private void doOnUnregisteredError(String errorId) {
    CallbackContext callback = callbackIds.get("unregisterDevice");
    if (callback == null) return;

    callback.error(errorId);
    callbackIds.remove("unregisterDevice");
  }
 private void checkLink(String message, CallbackContext callbackContext) {
   Log.v(TAG, "checkLink method executing");
   if (mDbxAcctMgr.hasLinkedAccount()) {
     callbackContext.success();
   } else {
     callbackContext.error("User not authenticated yet");
   }
 }
 public void handleRichPush(JSONArray array, CallbackContext callbackContext)
     throws JSONException {
   try {
     NetmeraPushService.handleRichPush(webView);
     callbackContext.success();
   } catch (NetmeraException e) {
     callbackContext.error(jsonError(e));
   }
 }
 public void unregister(JSONArray array, CallbackContext callbackContext) throws JSONException {
   NetmeraDeviceDetail deviceDetail;
   try {
     deviceDetail = jsonArraytoNetmeraDeviceDetail(array);
   } catch (NetmeraException e) {
     callbackContext.error(jsonError(e));
     return;
   }
   NetmeraPushService.unregister(deviceDetail);
   callbackContext.success();
 }
  /**
   * Executes the request and returns PluginResult.
   *
   * @param action The action to execute.
   * @param args JSONArry of arguments for the plugin.
   * @param callbackId The callback id used when calling back into JavaScript.
   * @return A PluginResult object with a status and message.
   */
  @Override
  public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
    try {
      if (action.equals("createVideoThumbnail")) {
        String pvUrl = args.getString(0);
        if (pvUrl != null && pvUrl.length() > 0) {
          // do smth with pvUrl

          // MINI_KIND: 512 x 384 thumbnail
          Bitmap bmThumbnail = ThumbnailUtils.createVideoThumbnail(pvUrl, Thumbnails.MINI_KIND);

          try {
            FileOutputStream out = new FileOutputStream(pvUrl + ".jpg");
            bmThumbnail.compress(Bitmap.CompressFormat.JPEG, 55, out);
            //	                	       File file = new File(pvUrl + ".jpg");
            //	                	       boolean val = file.exists();

          } catch (Exception e) {
            e.printStackTrace();
          }

          callbackContext.success(pvUrl + ".jpg");
          return true;
        }
      } else {
        if (action.equals("createImageThumbnail")) {
          String pvUrl = args.getString(0);
          if (pvUrl != null && pvUrl.length() > 0) {
            // do smth with pvUrl

            Bitmap bitmap = BitmapFactory.decodeFile(pvUrl);

            Bitmap bmThumbnail = ThumbnailUtils.extractThumbnail(bitmap, 512, 384);

            try {
              FileOutputStream out = new FileOutputStream(pvUrl + ".jpg");
              bmThumbnail.compress(Bitmap.CompressFormat.JPEG, 55, out);
            } catch (Exception e) {
              e.printStackTrace();
            }

            callbackContext.success(pvUrl + ".jpg");
            return true;
          }
        }
      }

    } catch (JSONException e) {

    }
    return false;
  }
  /*
   ************************************************************************************************
   * Private Methods
   ************************************************************************************************
   */
  private void sendUpdateToListener(ExecuteResult logicResult, Object[] listenerExtras) {
    try {
      if (listenerExtras != null && listenerExtras.length > 0) {
        Log.d(TAG, "Sending update");
        CallbackContext callback = (CallbackContext) listenerExtras[0];

        callback.sendPluginResult(transformResult(logicResult));

        Log.d(TAG, "Sent update");
      }
    } catch (Exception ex) {
      Log.d(TAG, "Sending update failed", ex);
    }
  }
    @Override
    public void onComplete(Bundle values) {
      String token = values.getString("access_token");
      String expires_in = values.getString("expires_in");

      JSONObject json = new JSONObject();
      try {
        json.put("token", token);
        json.put("expires_in", expires_in);
        callbackContext.success(json);
      } catch (JSONException e) {
        e.printStackTrace();
        callbackContext.error(getErrorObject(e.getMessage()));
      }
    }
  @Override
  public void onReceive(Context ctx, Intent intent) {

    // Get the SMS map from Intent
    Bundle extras = intent.getExtras();
    if (extras != null) {
      // Get received SMS Array
      Object[] smsExtra = (Object[]) extras.get(SMS_EXTRA_NAME);

      for (int i = 0; i < smsExtra.length; i++) {
        SmsMessage sms = SmsMessage.createFromPdu((byte[]) smsExtra[i]);
        if (this.isReceiving && this.callback_receive != null) {
          String formattedMsg = sms.getOriginatingAddress() + ">" + sms.getMessageBody();
          PluginResult result = new PluginResult(PluginResult.Status.OK, formattedMsg);
          result.setKeepCallback(true);
          callback_receive.sendPluginResult(result);
        }
      }

      // If the plugin is active and we don't want to broadcast to other receivers
      if (this.isReceiving && !broadcast) {
        this.abortBroadcast();
      }
    }
  }
Example #13
0
 @Override
 public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
   if (action.equals("show")) {
     this.showKeyBoard();
     callbackContext.success("done");
     return true;
   } else if (action.equals("hide")) {
     this.hideKeyBoard();
     callbackContext.success();
     return true;
   } else if (action.equals("isShowing")) {
     callbackContext.success(Boolean.toString(this.isKeyBoardShowing()));
     return true;
   } else {
     return false;
   }
 }
  private void connect(String url, CallbackContext callbackContext) {

    if (url != null && url.length() > 0) {
      try {
        this.uri = new URI(url);
        this.socketClient = new CordovaClient(uri, callbackContext);
        PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
        pluginResult.setKeepCallback(true);
        callbackContext.sendPluginResult(pluginResult);
        this.socketClient.connect();
      } catch (URISyntaxException e) {
        callbackContext.error("Not a valid URL");
      }
    } else {
      callbackContext.error("Not a valid URL");
    }
  }
  private boolean internalRegister(JSONArray data, CallbackContext callbackContext) {
    JSONObject params = null;
    try {
      params = data.getJSONObject(0);
    } catch (JSONException e) {
      e.printStackTrace();

      callbackContext.error(e.getMessage());
      return true;
    }

    callbackIds.put("registerDevice", callbackContext);

    try {
      String appid = null;
      if (params.has("appid")) appid = params.getString("appid");
      else appid = params.getString("pw_appid");

      mPushManager = new PushManager(cordova.getActivity(), appid, params.getString("projectid"));
    } catch (JSONException e) {
      callbackIds.remove("registerDevice");
      e.printStackTrace();

      callbackContext.error(e.getMessage());
      return true;
    }

    try {
      if (loggedStart) {
        mPushManager.onStartup(cordova.getActivity(), false);
      } else {
        mPushManager.onStartup(cordova.getActivity(), true);
        loggedStart = true;
      }
    } catch (java.lang.RuntimeException e) {
      callbackIds.remove("registerDevice");
      e.printStackTrace();

      callbackContext.error(e.getMessage());
      return true;
    }

    checkMessage(cordova.getActivity().getIntent());
    return true;
  }
  /**
   * Create a new plugin result and send it back to JavaScript
   *
   * @param connection the network info to set as navigator.connection
   */
  private void sendUpdate(String type) {
    if (connectionCallbackContext != null) {
      PluginResult result = new PluginResult(PluginResult.Status.OK, type);
      result.setKeepCallback(true);
      connectionCallbackContext.sendPluginResult(result);
    }

    webView.postMessage("networkconnection", type);
  }
  public void initialize(JSONArray params, CallbackContext callbackContext) throws JSONException {
    Context context = this.cordova.getActivity().getApplicationContext();

    String apiKey = params.getString(0);
    String senderId = params.getString(1);

    Netmera.init(context, apiKey);
    senderID = senderId;
    callbackContext.success();
  }
 public void onCancel(DialogInterface paramDialogInterface)
 {
   CallbackContext localCallbackContext;
   PluginResult.Status localStatus;
   if (this$1.val$negativeButton != null)
   {
     localCallbackContext = this$1.val$callbackContext;
     localStatus = PluginResult.Status.OK;
     if (!val$hasNeutralButton) {
       break label57;
     }
   }
   label57:
   for (int i = 2;; i = 1)
   {
     localCallbackContext.sendPluginResult(new PluginResult(localStatus, i));
     NotificationPlugin.access$000().remove(paramDialogInterface);
     return;
   }
 }
  public boolean execute(String action, JSONArray data, CallbackContext callbackContext) {
    if (!knownActions.contains(action)) {
      Logging.debug("ACTION", "Invalid action: " + action);
      callbackContext.error(jsonError("Action is unknown", 5555));
      return false;
    }
    try {
      Logging.debug("EXEC", "Plugin Execute: " + action);
      Method method =
          NetmeraPhoneGapPlugin.class.getDeclaredMethod(
              action, JSONArray.class, CallbackContext.class);
      method.invoke(this, data, callbackContext);
      return true;
    } catch (Exception e) {
      Logging.error("EXEC", e.getMessage(), e);
      callbackContext.error(jsonError("Method cannot be found", 5555));
    }

    return false;
  }
  public void getNotification(JSONArray array, CallbackContext callbackContext) {
    String message = NetmeraPhoneGapPlugin.message;
    Map<String, String> extras = NetmeraPhoneGapPlugin.extras;
    JSONObject obj = jsonNotification(message, extras);

    callbackContext.success(obj);

    // reset incoming push data until the next background push comes in
    NetmeraPhoneGapPlugin.message = "";
    NetmeraPhoneGapPlugin.extras = new HashMap<String, String>();
  }
 /**
  * Executes the request and returns PluginResult.
  *
  * @param action The action to execute.
  * @param args JSONArry of arguments for the plugin.
  * @param callbackContext The callback id used when calling back into JavaScript.
  * @return True if the action was valid, false otherwise.
  */
 public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
   if (action.equals("getConnectionInfo")) {
     this.connectionCallbackContext = callbackContext;
     NetworkInfo info = sockMan.getActiveNetworkInfo();
     PluginResult pluginResult =
         new PluginResult(PluginResult.Status.OK, this.getConnectionInfo(info));
     pluginResult.setKeepCallback(true);
     callbackContext.sendPluginResult(pluginResult);
     return true;
   }
   return false;
 }
  private boolean internalUnregister(JSONArray data, CallbackContext callbackContext) {
    callbackIds.put("unregisterDevice", callbackContext);

    try {
      GCMRegistrar.unregister(cordova.getActivity());
    } catch (Exception e) {
      callbackIds.remove("unregisterDevice");
      callbackContext.error(e.getMessage());
      return true;
    }

    return true;
  }
Example #23
0
  @Override
  public boolean execute(String action, JSONArray args, CallbackContext callbackContext)
      throws JSONException {
    Intent batteryIntent =
        this.cordova
            .getActivity()
            .registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
    int level = batteryIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
    int scale = batteryIntent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);

    callbackContext.success(
        new JSONObject().put("returnVal", (((float) level / (float) scale) * 100.0f)));
    return true;
  }
  private boolean internalSendTags(JSONArray data, CallbackContext callbackContext) {
    JSONObject params;
    try {
      params = data.getJSONObject(0);
    } catch (JSONException e) {
      e.printStackTrace();
      return false;
    }

    @SuppressWarnings("unchecked")
    Iterator<String> nameItr = params.keys();
    Map<String, Object> paramsMap = new HashMap<String, Object>();
    while (nameItr.hasNext()) {
      try {
        String name = nameItr.next();
        paramsMap.put(name, params.get(name));
      } catch (JSONException e) {
        e.printStackTrace();
        return false;
      }
    }

    try {
      Map<String, String> skippedTags =
          PushManager.sendTagsFromBG(cordova.getActivity(), paramsMap);

      JSONObject skippedTagsObj = new JSONObject();
      for (String tagName : skippedTags.keySet()) {
        skippedTags.put(tagName, skippedTags.get(tagName));
      }

      callbackContext.success(skippedTagsObj);
      return true;
    } catch (PushWooshException e) {
      e.printStackTrace();
      return false;
    }
  }
 @Override
 public void onWeiboException(WeiboException e) {
   callbackContext.error(getErrorObject(e.getMessage()));
 }
 @Override
 public void onError(WeiboDialogError e) {
   callbackContext.error(getErrorObject(e.getMessage()));
 }
 private void link(String message, CallbackContext callbackContext) {
   Log.v(TAG, "link method executing");
   mDbxAcctMgr.startLink(cordova.getActivity(), REQUEST_LINK_TO_DBX);
   callbackContext.success();
 }
 private void unlink(String message, CallbackContext callbackContext) {
   Log.v(TAG, "unlink method executing");
   mDbxAcctMgr.unlink();
   callbackContext.success();
 }
  @Override
  public boolean execute(String action, JSONArray args, final CallbackContext callbackContext)
      throws JSONException {
    System.out.println("MADE IT HERE..." + action);
    JSONObject parameters = args.getJSONObject(0);

    if (action.equals(ACTION_HAS_SMS_POSSIBILITY)) {

      Activity ctx = this.cordova.getActivity();
      if (ctx.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, true));
      } else {
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, false));
      }
      return true;
    } else if (action.equals(ACTION_SEND_SMS)) {
      System.out.println("MADE INTO HERE TOO...");
      try {
        System.out.println(parameters.toString());
        JSONArray phoneNumbers = parameters.getJSONArray("toRecipients");
        System.out.println("json 1 worked");
        System.out.println("1" + phoneNumbers.length());
        System.out.println("2" + phoneNumbers.toString());
        System.out.println("3" + phoneNumbers.get(0));
        System.out.println("4" + phoneNumbers.getString(0));
        String[] numbers = null;

        String message = parameters.getString("body");
        System.out.println("json 2 worked");
        System.out.println(message);

        if (phoneNumbers != null
            && phoneNumbers.length() > 0
            && phoneNumbers.toString().equals("[\"\"]")) {
          numbers = new String[phoneNumbers.length()];
          System.out.println("string array created");
          for (int i = 0; i < phoneNumbers.length(); i++) {
            numbers[i] = phoneNumbers.getString(i);
            System.out.println(numbers[i]);
          }

          this.sendSMS(numbers, message);
        } else {
          this.openSMSComposer(message); // if the list is empty, open
          // composer instead.
        }

        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK));
      } catch (JSONException ex) {
        System.out.println("JSON ERRORS");
        callbackContext.sendPluginResult(
            new PluginResult(PluginResult.Status.ERROR, ex.getMessage()));
      } catch (Exception e) {
        System.out.println("Error handling: " + e.toString());
      }

      return true;
    }
    System.out.println("Error with api");
    callbackContext.sendPluginResult(
        new PluginResult(PluginResult.Status.ERROR, "Error, action doesnt fit api"));
    return false;
  }