@Override
 public boolean execute(String action, JSONArray data, CallbackContext callbackContext)
     throws JSONException {
   if (action.equals("storeMeasurement")) {
     Context ctxt = cordova.getActivity();
     (new ClientStatsHelper(ctxt))
         .storeMeasurement(
             data.getString(0), // key
             data.getString(1), // value
             data.getString(2)); // ts
     callbackContext.success();
     return true;
   } else if (action.equals("storeEventNow")) {
     Context ctxt = cordova.getActivity();
     new ClientStatsHelper(ctxt)
         .storeMeasurement(
             data.getString(0), // key
             null, // value
             String.valueOf(System.currentTimeMillis())); // ts
     callbackContext.success();
     return true;
   } else {
     return false;
   }
 }
  @Override
  public boolean execute(String action, JSONArray args, final CallbackContext callbackContext)
      throws JSONException {
    if (action.equals("upload") || action.equals("download")) {
      String source = args.getString(0);
      String target = args.getString(1);

      if (action.equals("upload")) {
        upload(source, target, args, callbackContext);
      } else {
        download(source, target, args, callbackContext);
      }
      return true;
    } else if (action.equals("abort")) {
      String objectId = args.getString(0);
      abort(objectId);
      callbackContext.success();
      return true;
    } else if (action.equals("pause")) {
      String objectId = args.getString(0);
      pause(objectId);
      callbackContext.success();
      return true;
    }
    return false;
  }
  /**
   * Executes the request.
   *
   * @param action the action to execute.
   * @param args the exec() arguments.
   * @param callbackContext the callback context used when calling back into JavaScript.
   * @return whether the action was valid.
   */
  public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) {

    if (action.equalsIgnoreCase("init")) {
      if (logger != null) {
        logger.stop();
      }
      String[] sensors;
      try {
        JSONArray strings = args.getJSONArray(0);
        sensors = new String[strings.length()];
        for (int i = 0; i < strings.length(); i++) sensors[i] = strings.getString(i);
      } catch (JSONException ex) {
        callbackContext.error(ex.getMessage());
        return true;
      }
      try {
        logger = new SensorLogger(this.view.getContext(), sensors);
      } catch (IOException ex) {
        callbackContext.error(ex.getMessage());
        return true;
      }

      callbackContext.success();
      return true;
    } else if (action.equalsIgnoreCase("start")) {
      logger.start();
      callbackContext.success();
      return true;
    } else if (action.equalsIgnoreCase("stop")) {
      logger.stop();
      callbackContext.success();
      return true;
    }
    return false;
  }
 void isPushStopped(JSONArray data, CallbackContext callbackContext) {
   boolean isStopped =
       JPushInterface.isPushStopped(this.cordova.getActivity().getApplicationContext());
   if (isStopped) {
     callbackContext.success(1);
   } else {
     callbackContext.success(0);
   }
 }
  @Override
  public boolean execute(String action, CordovaArgs args, CallbackContext callbackContext)
      throws JSONException {
    this.savedCallbackContext = callbackContext;

    if (args.optJSONObject(0) != null) {
      JSONObject obj = args.getJSONObject(0);
      this.webKey = obj.optString(ARGUMENT_WEB_KEY, null);
      this.apiKey = obj.optString(ARGUMENT_ANDROID_KEY, null);
      this.requestOfflineToken = obj.optBoolean(ARGUMENT_OFFLINE_KEY, false);
      this.setupScopes(obj.optString(ARGUMENT_SCOPES, null));
      // possible scope change, so force a rebuild of the client
      this.mGoogleApiClient = null;
    }

    // It's important that we build the GoogleApiClient after setting up scopes so we know which
    // scopes to request when setting up the google services api client.
    buildGoogleApiClient();

    if (ACTION_IS_AVAILABLE.equals(action)) {
      final boolean avail =
          GooglePlayServicesUtil.isGooglePlayServicesAvailable(
                  this.cordova.getActivity().getApplicationContext())
              == 0;
      savedCallbackContext.success("" + avail);

    } else if (ACTION_LOGIN.equals(action)) {
      this.trySilentLogin = false;
      mGoogleApiClient.reconnect();

    } else if (ACTION_TRY_SILENT_LOGIN.equals(action)) {
      this.trySilentLogin = true;
      mGoogleApiClient.reconnect();

    } else if (ACTION_LOGOUT.equals(action)) {
      try {
        Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
        mGoogleApiClient.disconnect();
        // needed in onActivityResult when the connect method below comes back
        loggingOut = true;
        buildGoogleApiClient();
        mGoogleApiClient.connect();
      } catch (IllegalStateException ignore) {
      }
      savedCallbackContext.success("logged out");

    } else if (ACTION_DISCONNECT.equals(action)) {
      disconnect();
    } else {
      return false;
    }
    return true;
  }
예제 #6
0
  @Override
  public boolean execute(String action, JSONArray data, CallbackContext callbackContext) {

    boolean result = false;

    Log.v(TAG, "execute: action=" + action);

    if (REGISTER.equals(action)) {

      Log.v(TAG, "execute: data=" + data.toString());

      try {
        JSONObject jo = data.getJSONObject(0);

        gWebView = this.webView;
        Log.v(TAG, "execute: jo=" + jo.toString());

        gECB = (String) jo.get("ecb");
        gSenderID = (String) jo.get("senderID");

        Log.v(TAG, "execute: ECB=" + gECB + " senderID=" + gSenderID);

        GCMRegistrar.register(getApplicationContext(), gSenderID);
        result = true;
        callbackContext.success();
      } catch (JSONException e) {
        Log.e(TAG, "execute: Got JSON Exception " + e.getMessage());
        result = false;
        callbackContext.error(e.getMessage());
      }

      if (gCachedExtras != null) {
        Log.v(TAG, "sending cached extras");
        sendExtras(gCachedExtras);
        gCachedExtras = null;
      }

    } else if (UNREGISTER.equals(action)) {

      GCMRegistrar.unregister(getApplicationContext());

      Log.v(TAG, "UNREGISTER");
      result = true;
      callbackContext.success();
    } else {
      result = false;
      Log.e(TAG, "Invalid action : " + action);
      callbackContext.error("Invalid action : " + action);
    }

    return result;
  }
  /**
   * Executes the request and returns PluginResult.
   *
   * @param action The action to execute
   * @param args JSONArray of arguments for the plugin.
   * @param callbackContext The callback id used when calling back into JavaScript
   * @return True if the action was valid, otherwise false
   */
  @Override
  public boolean execute(String action, JSONArray args, CallbackContext callbackContext)
      throws JSONException {
    Log.d(EstimoteBeacons.class.toString(), "action -> " + action);

    try {
      if (action.equalsIgnoreCase(START_MONITORING_BEACONS_IN_REGION)) {
        startMonitoringBeaconsInRegion(callbackContext);
        return true;
      }

      if (action.equalsIgnoreCase(STOP_MONITORING_BEACONS_IN_REGION)) {
        stopMonitoringBeaconsInRegion();
        callbackContext.success(callbackContext.getCallbackId());
        return true;
      }

      if (action.equalsIgnoreCase(START_RANGING_BEACONS_IN_REGION)) {
        startRangingBeaconsInRegion();
        callbackContext.success(callbackContext.getCallbackId());
        return true;
      }

      if (action.equalsIgnoreCase(STOP_RANGING_BEACONS_IN_REGION)) {
        stopRangingBeaconsInRegion();
        callbackContext.success(callbackContext.getCallbackId());
        return true;
      }

      if (action.equalsIgnoreCase(GET_BEACONS)) {
        callbackContext.sendPluginResult(
            new PluginResult(PluginResult.Status.OK, listToJSONArray(beacons)));
        return true;
      }

      if (action.equalsIgnoreCase(IS_BLE_SUPPORTED)) {
        isBleSupported(callbackContext);
        return true;
      }

      if (action.equalsIgnoreCase(IS_BLUETOOTH_ENABLED)) {
        isBluetoothEnabled(callbackContext);
        return true;
      }
    } catch (Exception e) {
      System.out.println(e.getMessage());
      callbackContext.error(e.getMessage());
      return false;
    }
    return false;
  }
  private void executeLogEvent(JSONArray args, CallbackContext callbackContext)
      throws JSONException {
    if (args.length() == 0) {
      // Not enough parameters
      callbackContext.error("Invalid arguments");
      return;
    }

    String eventName = args.getString(0);
    if (args.length() == 1) {
      logger.logEvent(eventName);
      callbackContext.success();
      return;
    }

    // Arguments is greater than 1
    JSONObject params = args.getJSONObject(1);
    Bundle parameters = new Bundle();
    Iterator<String> iter = params.keys();

    while (iter.hasNext()) {
      String key = iter.next();
      try {
        // Try get a String
        String value = params.getString(key);
        parameters.putString(key, value);
      } catch (JSONException e) {
        // Maybe it was an int
        Log.w(TAG, "Type in AppEvent parameters was not String for key: " + key);
        try {
          int value = params.getInt(key);
          parameters.putInt(key, value);
        } catch (JSONException e2) {
          // Nope
          Log.e(TAG, "Unsupported type in AppEvent parameters for key: " + key);
        }
      }
    }

    if (args.length() == 2) {
      logger.logEvent(eventName, parameters);
      callbackContext.success();
    }

    if (args.length() == 3) {
      double value = args.getDouble(2);
      logger.logEvent(eventName, value, parameters);
      callbackContext.success();
    }
  }
  @Override
  public boolean execute(String action, JSONArray args, final CallbackContext callbackContext)
      throws JSONException {
    if (action.equals("upload") || action.equals("download")) {
      String source = args.getString(0);
      String target = args.getString(1);

      if (action.equals("upload")) {
        try {
          source = URLDecoder.decode(source, "UTF-8");
          upload(source, target, args, callbackContext);
        } catch (UnsupportedEncodingException e) {
          callbackContext.sendPluginResult(
              new PluginResult(PluginResult.Status.MALFORMED_URL_EXCEPTION, "UTF-8 error."));
        }
      } else {
        download(source, target, args, callbackContext);
      }
      return true;
    } else if (action.equals("abort")) {
      String objectId = args.getString(0);
      abort(objectId);
      callbackContext.success();
      return true;
    }
    return false;
  }
예제 #10
0
  /**
   * Open a database.
   *
   * @param dbName The name of the database file
   */
  private SQLiteAndroidDatabase openDatabase(String dbname, CallbackContext cbc, boolean old_impl)
      throws Exception {
    try {
      // ASSUMPTION: no db (connection/handle) is already stored in the map
      // [should be true according to the code in DBRunner.run()]

      File dbfile = this.cordova.getActivity().getDatabasePath(dbname);

      if (!dbfile.exists()) {
        dbfile.getParentFile().mkdirs();
      }

      Log.v("info", "Open sqlite db: " + dbfile.getAbsolutePath());

      SQLiteAndroidDatabase mydb = old_impl ? new SQLiteAndroidDatabase() : new SQLiteDatabaseNDK();
      mydb.open(dbfile);

      if (cbc != null) // XXX Android locking/closing BUG workaround
      cbc.success();

      return mydb;
    } catch (Exception e) {
      if (cbc != null) // XXX Android locking/closing BUG workaround
      cbc.error("can't open database " + e);
      throw e;
    }
  }
  @Override
  public boolean execute(String action, JSONArray args, final CallbackContext callbackContext)
      throws JSONException {
    WifiManager wifiMgr =
        (WifiManager) cordova.getActivity().getSystemService(Context.WIFI_SERVICE);
    DhcpInfo ipConfig = wifiMgr.getDhcpInfo();

    if (IpUtils.toIpv4(ipConfig.ipAddress).compareTo("0.0.0.0") != 0) {
      netConfig.put("ipAddress", IpUtils.toIpv4(ipConfig.ipAddress));
    }
    netConfig.put("ipAddress", IpUtils.toIpv4(ipConfig.ipAddress));
    netConfig.put("macAddress", wifiMgr.getConnectionInfo().getMacAddress());
    netConfig.put("netmask", IpUtils.toIpv4(ipConfig.netmask));
    netConfig.put("gateway", IpUtils.toIpv4(ipConfig.gateway));
    netConfig.put("dns1", IpUtils.toIpv4(ipConfig.dns1));
    netConfig.put("dns2", IpUtils.toIpv4(ipConfig.dns1));

    if (netConfig != null) {
      callbackContext.success(netConfig);
      return true;
    } else {
      callbackContext.error("Operation failed");

      return false;
    }
  }
예제 #12
0
  @Override
  public boolean execute(String action, JSONArray args, CallbackContext callbackContext)
      throws JSONException {
    this.callbackContext = callbackContext;
    this.limit = 1;
    this.duration = 0;
    this.results = new JSONArray();

    JSONObject options = args.optJSONObject(0);
    if (options != null) {
      limit = options.optLong("limit", 1);
      duration = options.optInt("duration", 0);
    }

    if (action.equals("getFormatData")) {
      JSONObject obj = getFormatData(args.getString(0), args.getString(1));
      callbackContext.success(obj);
      return true;
    } else if (action.equals("captureAudio")) {
      this.captureAudio();
    } else if (action.equals("captureImage")) {
      this.captureImage();
    } else if (action.equals("captureVideo")) {
      this.captureVideo(duration);
    } else {
      return false;
    }

    return true;
  }
 /**
  * Busca todos os dispositivos Bluetooth pareados com o device
  *
  * @param callbackContext
  */
 protected void getBluetoothPairedDevices(CallbackContext callbackContext) {
   BluetoothAdapter mBluetoothAdapter = null;
   try {
     mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
     if (mBluetoothAdapter == null) {
       callbackContext.error(this.getErrorByCode(1));
       return;
     }
     if (!mBluetoothAdapter.isEnabled()) {
       Intent enableBluetooth = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
       this.mCordova.getActivity().startActivityForResult(enableBluetooth, 0);
     }
     Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
     if (pairedDevices.size() > 0) {
       JSONArray json = new JSONArray();
       for (BluetoothDevice device : pairedDevices) {
         Hashtable map = new Hashtable();
         map.put("type", device.getType());
         map.put("address", device.getAddress());
         map.put("name", device.getName());
         JSONObject jObj = new JSONObject(map);
         json.put(jObj);
       }
       callbackContext.success(json);
     } else {
       callbackContext.error(this.getErrorByCode(2));
     }
   } catch (Exception e) {
     Log.e(LOG_TAG, e.getMessage());
     e.printStackTrace();
     callbackContext.error(e.getMessage());
   }
 }
  private void addTransactionItem(
      String id,
      String name,
      String sku,
      String category,
      double price,
      long quantity,
      String currencyCode,
      CallbackContext callbackContext) {
    if (!trackerStarted) {
      callbackContext.error("Tracker not started");
      return;
    }

    if (null != id && id.length() > 0) {
      HitBuilders.ItemBuilder hitBuilder = new HitBuilders.ItemBuilder();
      addCustomDimensionsToHitBuilder(hitBuilder);

      tracker.send(
          hitBuilder
              .setTransactionId(id)
              .setName(name)
              .setSku(sku)
              .setCategory(category)
              .setPrice(price)
              .setQuantity(quantity)
              .setCurrencyCode(currencyCode)
              .build()); // Deprecated
      callbackContext.success("Add Transaction Item: " + id);
    } else {
      callbackContext.error("Expected non-empty ID.");
    }
  }
  private void trackEvent(
      String category,
      String deepLinkUrl,
      String action,
      String label,
      long value,
      CallbackContext callbackContext) {
    if (!trackerStarted) {
      callbackContext.error("Tracker not started");
      return;
    }

    addCustomDimensionsToTracker(tracker);

    if (null != category && category.length() > 0) {
      tracker.send(
          new HitBuilders.EventBuilder()
              .setCampaignParamsFromUrl(deepLinkUrl)
              .setCategory(category)
              .setAction(action)
              .setLabel(label)
              .setValue(value)
              .build());
      callbackContext.success("Track Event: " + category);
    } else {
      callbackContext.error("Expected non-empty string arguments.");
    }
  }
예제 #16
0
 private void sum(Integer num1, Integer num2, CallbackContext callbackContext) {
   if (num1 != null && num2 != null) {
     callbackContext.success(num1 + num2);
   } else {
     callbackContext.error("Expected two integer arguments.");
   }
 }
  public boolean execute(String action, JSONArray args, CallbackContext callbackContext)
      throws JSONException {
    if (action.equals("checkPasscodeStatus")) {

      if (doesDeviceHaveSecuritySetup(this.cordova.getActivity())) {
        String message = "true";
        callbackContext.success(message);
      } else {
        String message = "false";
        callbackContext.success(message);
      }

      return true;
    }
    return false;
  }
    /** Return a string containing the date in the format YYYY/MM/DD */
    public void onDateSet(
        final DatePicker view, final int year, final int monthOfYear, final int dayOfMonth) {
      String dateValue =
          Integer.toString(year)
              + "-"
              + pad(Integer.toString(monthOfYear + 1))
              + "-"
              + pad(Integer.toString(dayOfMonth))
              + "T00:00:00";

      SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
      dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
      Date date;
      JSONObject message;
      try {
        date = dateFormat.parse(dateValue);
        message = new JSONObject();
        try {
          message.put("date", date.getTime());
          message.put("changed", false);
          callbackContext.success(message);
        } catch (org.json.JSONException e) {
          e.printStackTrace();
        }
      } catch (ParseException e) {
        e.printStackTrace();
      }
    }
  @Override
  public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {

    if (action.equals("getBluetoothMacAddress")) {

      String macAddress = this.getBluetoothMacAddress();

      if (macAddress != null) {
        JSONObject JSONresult = new JSONObject();
        try {
          JSONresult.put("mac", macAddress);
          PluginResult r = new PluginResult(PluginResult.Status.OK, JSONresult);
          callbackContext.success(macAddress);
          r.setKeepCallback(true);
          callbackContext.sendPluginResult(r);
          return true;
        } catch (JSONException jsonEx) {
          PluginResult r = new PluginResult(PluginResult.Status.JSON_EXCEPTION);
          callbackContext.error("error");
          r.setKeepCallback(true);
          callbackContext.sendPluginResult(r);
          return true;
        }
      }
    }
    return false;
  }
예제 #20
0
 /**
  * Adds a listener to a specific namespace
  *
  * @param namespace
  * @param callbackContext
  * @return
  */
 public boolean addMessageListener(String namespace, CallbackContext callbackContext) {
   if (this.currentSession != null) {
     this.currentSession.addMessageListener(namespace);
     callbackContext.success();
   }
   return true;
 }
 private void coolMethod(String message, CallbackContext callbackContext) {
   if (message != null && message.length() > 0) {
     callbackContext.success(message);
   } else {
     callbackContext.error("Expected one non-empty string argument.");
   }
 }
  public void sendSingleTextMessage(JSONArray data, CallbackContext callbackContext) {
    Log.i(TAG, " sendSingleTextMessage \n" + data);

    final CallbackContext cb = callbackContext;
    try {
      String username = data.getString(0);
      String text = data.getString(1);

      Conversation conversation = JMessageClient.getSingleConversation(username);
      if (conversation == null) {
        conversation = Conversation.createSingleConversation(username);
      }
      if (conversation == null) {
        callbackContext.error("无法创建对话");
        return;
      }
      TextContent content = new TextContent(text);
      final Message msg = conversation.createSendMessage(content);

      JMessageClient.sendMessage(msg);
      callbackContext.success("正在发送");

    } catch (JSONException e) {
      e.printStackTrace();
      callbackContext.error("error reading id json");
    }
  }
  private void trackTiming(
      String category,
      long intervalInMilliseconds,
      String name,
      String label,
      CallbackContext callbackContext) {
    if (!trackerStarted) {
      callbackContext.error("Tracker not started");
      return;
    }

    if (null != category && category.length() > 0) {
      HitBuilders.TimingBuilder hitBuilder = new HitBuilders.TimingBuilder();
      addCustomDimensionsToHitBuilder(hitBuilder);

      tracker.send(
          hitBuilder
              .setCategory(category)
              .setValue(intervalInMilliseconds)
              .setVariable(name)
              .setLabel(label)
              .build());
      callbackContext.success("Track Timing: " + category);
    } else {
      callbackContext.error("Expected non-empty string arguments.");
    }
  }
예제 #24
0
  /**
   * Selects a route by its id
   *
   * @param routeId
   * @param callbackContext
   * @return
   */
  public boolean selectRoute(final String routeId, final CallbackContext callbackContext) {
    if (this.currentSession != null) {
      callbackContext.success(this.currentSession.createSessionObject());
      return true;
    }

    this.setLastSessionId("");

    final Activity activity = cordova.getActivity();
    activity.runOnUiThread(
        new Runnable() {
          public void run() {
            mMediaRouter = MediaRouter.getInstance(activity.getApplicationContext());
            final List<RouteInfo> routeList = mMediaRouter.getRoutes();

            for (RouteInfo route : routeList) {
              if (route.getId().equals(routeId)) {
                Chromecast.this.createSession(route, callbackContext);
                return;
              }
            }

            callbackContext.error("No route found");
          }
        });

    return true;
  }
  private void addTransaction(
      String id,
      String affiliation,
      double revenue,
      double tax,
      double shipping,
      String currencyCode,
      CallbackContext callbackContext) {
    if (!trackerStarted) {
      callbackContext.error("Tracker not started");
      return;
    }

    if (null != id && id.length() > 0) {
      HitBuilders.TransactionBuilder hitBuilder = new HitBuilders.TransactionBuilder();
      addCustomDimensionsToHitBuilder(hitBuilder);

      tracker.send(
          hitBuilder
              .setTransactionId(id)
              .setAffiliation(affiliation)
              .setRevenue(revenue)
              .setTax(tax)
              .setShipping(shipping)
              .setCurrencyCode(currencyCode)
              .build()); // Deprecated
      callbackContext.success("Add Transaction: " + id);
    } else {
      callbackContext.error("Expected non-empty ID.");
    }
  }
  void setTags(JSONArray data, CallbackContext callbackContext) {

    HashSet<String> tags = null;
    try {
      String tagStr;
      if (data == null) {
        // tags=null;
      } else if (data.length() == 0) {
        tags = new HashSet<String>();
      } else {
        tagStr = data.getString(0);
        String[] tagArray = tagStr.split(",");
        for (String tag : tagArray) {
          if (tags == null) {
            tags = new HashSet<String>();
          }
          tags.add(tag);
        }
      }
      // Set<String> validTags = JPushInterface.filterValidTags(tags);
      JPushInterface.setTags(
          this.cordova.getActivity().getApplicationContext(), tags, mTagWithAliasCallback);
      callbackContext.success();
    } catch (JSONException e) {
      e.printStackTrace();
      callbackContext.error("Error reading tags JSON");
    }
  }
    /** Return the current date with the time modified as it was set in the time picker. */
    public void onTimeSet(final TimePicker view, final int hourOfDay, final int minute) {
      Date date = new Date();
      date.setHours(hourOfDay);
      date.setMinutes(minute);

      callbackContext.success(date.toLocaleString());
    }
예제 #28
0
  @Override
  public boolean execute(String action, JSONArray data, CallbackContext callbackContext)
      throws JSONException {

    if (action.equals(ACTION)) {

      String base64 = data.optString(0);
      if (base64.equals("")) // isEmpty() requires API level 9
      callbackContext.error("Missing base64 string");

      // Create the bitmap from the base64 string
      Log.d("Canvas2ImagePlugin", base64);
      byte[] decodedString = Base64.decode(base64, Base64.DEFAULT);
      Bitmap bmp = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
      if (bmp == null) {
        callbackContext.error("The image could not be decoded");
      } else {

        // Save the image
        File imageFile = savePhoto(bmp);
        if (imageFile == null) callbackContext.error("Error while saving image");

        // Update image gallery
        scanPhoto(imageFile);

        callbackContext.success(imageFile.toString());
      }

      return true;
    } else {
      return false;
    }
  }
  @Override
  public boolean execute(String action, JSONArray args, CallbackContext callbackContext)
      throws JSONException {
    try {
      if (ACTION_ADD_CALENDAR_ENTRY.equals(action)) {
        JSONObject arg_object = args.getJSONObject(0);
        Intent calIntent =
            new Intent(Intent.ACTION_EDIT)
                .setType("vnd.android.cursor.item/event")
                .putExtra("beginTime", arg_object.getLong("startTimeMillis"))
                .putExtra("endTime", arg_object.getLong("endTimeMillis"))
                .putExtra("title", arg_object.getString("title"))
                .putExtra("description", arg_object.getString("description"))
                .putExtra("eventLocation", arg_object.getString("eventLocation"));

        this.cordova.getActivity().startActivity(calIntent);
        callbackContext.success();
        return true;
      }
      callbackContext.error("Invalid action");
      return false;
    } catch (Exception e) {
      System.err.println("Exception: " + e.getMessage());
      callbackContext.error(e.getMessage());
      return false;
    }
  }
  private void getPermissions(CallbackContext callbackContext) throws JSONException {
    Session session = getSession();

    if (!session.getState().isOpened()) {
      callbackContext.success("login_required");
      return;
    }
    Log.d(TAG, "Permissions: " + Arrays.toString(session.getPermissions().toArray()));
    JSONObject response = new JSONObject();

    for (String permission : session.getPermissions()) {
      response.put(permission, 1);
    }

    callbackContext.success(response);
  }