@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;
  }
Esempio n. 2
0
  @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();
      }
    }
  }
  /**
   * 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);
  }
 /**
  * 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 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);
    }
  }
  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");
    }
  }
 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;
   }
 }
  @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;
  }