private boolean readTokenCacheItems(String authority) throws JSONException {

    final AuthenticationContext authContext;
    try {
      authContext = getOrCreateContext(authority);
    } catch (Exception e) {
      callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, e.getMessage()));
      return true;
    }

    JSONArray result = new JSONArray();
    ITokenCacheStore cache = authContext.getCache();

    if (cache instanceof ITokenStoreQuery) {
      Iterator<TokenCacheItem> cacheItems = ((ITokenStoreQuery) cache).getAll();

      while (cacheItems.hasNext()) {
        TokenCacheItem item = cacheItems.next();
        result.put(tokenItemToJSON(item));
      }
    }

    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result));

    return true;
  }
 /**
  * Executes the request and returns PluginResult.
  *
  * @param action The action to execute.
  * @param args JSONArry of arguments for the plugin.
  * @param callbackS=Context The callback id used when calling back into JavaScript.
  * @return True if the action was valid.
  * @throws JSONException
  */
 public boolean execute(String action, JSONArray args, CallbackContext callbackContext)
     throws JSONException {
   if (action.equals("start")) {
     this.start();
   } else if (action.equals("stop")) {
     this.stop();
   } else if (action.equals("getProximityState")) {
     // If not running, then this is an async call, so don't worry about waiting
     if (this.status != ProximitySensorListener.RUNNING) {
       int r = this.start();
       if (r == ProximitySensorListener.ERROR_FAILED_TO_START) {
         callbackContext.sendPluginResult(
             new PluginResult(
                 PluginResult.Status.IO_EXCEPTION, ProximitySensorListener.ERROR_FAILED_TO_START));
         return true;
       }
       // Set a timeout callback on the main thread.
       Handler handler = new Handler(Looper.getMainLooper());
       handler.postDelayed(
           new Runnable() {
             public void run() {
               ProximitySensorListener.this.timeout();
             }
           },
           2000);
     }
     callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, getProximity()));
   } else {
     // Unsupported action
     return false;
   }
   return true;
 }
  private boolean executeInitWithAppID(JSONArray inputs, CallbackContext callbackContext) {
    JSONObject args;

    // Get the input data.
    String strEnv = "ENV_NONE";
    try {
      args = inputs.getJSONObject(0);
      this.appId = args.getString("appId");
      strEnv = args.getString("appEnv");
    } catch (JSONException exception) {
      Log.w(LOGTAG, String.format("Got JSON Exception: %s", exception.getMessage()));
      callbackContext.sendPluginResult(new PluginResult(Status.JSON_EXCEPTION));
      return true;
    }

    if (strEnv.equals("ENV_LIVE")) {
      this.appEnv = PayPal.ENV_LIVE;
    } else if (strEnv.equals("ENV_SANDBOX")) {
      this.appEnv = PayPal.ENV_SANDBOX;
    } else {
      this.appEnv = PayPal.ENV_NONE;
    }

    Log.d(LOGTAG, "init paypal for " + this.appId + " with " + strEnv);

    PayPal.initWithAppID(cordova.getActivity(), this.appId, this.appEnv);
    callbackContext.sendPluginResult(new PluginResult(Status.OK));

    return true;
  }
Example #4
0
  private void errorCallback(final String returnInfo) {
    if (geofencingCallbacks == null) {
      JSONObject returnErrorInfo = new JSONObject();
      try {
        returnErrorInfo.put("code", DGLocationStatus.PERMISSIONDENIED.getStatusCode());
        returnErrorInfo.put("message", "At first, Please call initCallbackForRegionMonitoring().");
      } catch (JSONException ex) {
        currentCallbacks.sendPluginResult(
            new PluginResult(PluginResult.Status.ERROR, ex.toString()));
        return;
      }

      currentCallbacks.sendPluginResult(
          new PluginResult(PluginResult.Status.ERROR, returnErrorInfo));
    } else {
      cordova
          .getThreadPool()
          .execute(
              new Runnable() {
                public void run() {

                  PluginResult result = new PluginResult(PluginResult.Status.ERROR, returnInfo);
                  result.setKeepCallback(true);
                  geofencingCallbacks.sendPluginResult(result);
                }
              });
    }
  }
 @Override
 public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
     this.callbackContext = callbackContext;
     Log.d("WIFI", action);
     if(ACTION_START.equals(action)){
         PluginResult pgRes = new PluginResult(PluginResult.Status.OK, "Registered");
         pgRes.setKeepCallback(true);
         mWifiManager = (WifiManager) this.cordova.getActivity().getSystemService(Context.WIFI_SERVICE);
         this.reciever = new BroadcastReceiver()
         {
             @Override
             public void onReceive(Context c, Intent intent)
             {
                List<ScanResult> scanResults = mWifiManager.getScanResults();
                handleResults(scanResults);
             }
         };
         this.cordova.getActivity().registerReceiver(this.reciever, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
         callbackContext.sendPluginResult(pgRes);
         Log.d("WIFI", "inside " + action);
         return true;
     } else if (ACTION_SCAN.equals(action)){
         PluginResult pgRes = new PluginResult(PluginResult.Status.OK, []);
         pgRes.setKeepCallback(true);
         mWifiManager = (WifiManager) this.cordova.getActivity().getSystemService(Context.WIFI_SERVICE);
         mWifiManager.startScan();
         callbackContext.sendPluginResult(pgRes);
         Log.d("WIFI", "inside " + action);
         return true;
     } else if (ACTION_STOP.equals(action)){
 @Override
 public boolean execute(String action, JSONArray args, CallbackContext callbackContext)
     throws JSONException {
   PluginResult.Status status = PluginResult.Status.OK;
   String result = "";
   this.callbackContext = callbackContext;
   try {
     if (action.equals("takePicture")) {
       this.targetHeight = 0;
       this.targetWidth = 0;
       this.mQuality = 80;
       this.targetHeight = args.getInt(4);
       this.targetWidth = args.getInt(3);
       this.mQuality = args.getInt(0);
       this.takePicture();
       PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT);
       r.setKeepCallback(true);
       callbackContext.sendPluginResult(r);
       return true;
     }
     return false;
   } catch (JSONException e) {
     e.printStackTrace();
     callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
     return true;
   }
 }
  @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;
  }
  /**
   * 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 A PluginResult object with a status and message.
   */
  public boolean execute(String action, JSONArray args, CallbackContext callbackContext)
      throws JSONException {
    this.callbackContext = callbackContext;

    if (action.equals("takePicture")) {
      int srcType = CAMERA;
      int destType = FILE_URI;
      this.saveToPhotoAlbum = false;
      this.targetHeight = 0;
      this.targetWidth = 0;
      this.encodingType = JPEG;
      this.mediaType = PICTURE;
      this.mQuality = 80;

      this.mQuality = args.getInt(0);
      destType = args.getInt(1);
      srcType = args.getInt(2);
      this.targetWidth = args.getInt(3);
      this.targetHeight = args.getInt(4);
      this.encodingType = args.getInt(5);
      this.mediaType = args.getInt(6);
      // this.allowEdit = args.getBoolean(7); // This field is unused.
      this.correctOrientation = args.getBoolean(8);
      this.saveToPhotoAlbum = args.getBoolean(9);

      // If the user specifies a 0 or smaller width/height
      // make it -1 so later comparisons succeed
      if (this.targetWidth < 1) {
        this.targetWidth = -1;
      }
      if (this.targetHeight < 1) {
        this.targetHeight = -1;
      }

      try {
        if (srcType == CAMERA) {
          this.takePicture(destType, encodingType);
        } else if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) {
          this.getImage(srcType, destType);
        }
      } catch (IllegalArgumentException e) {
        callbackContext.error("Illegal Argument Exception");
        PluginResult r = new PluginResult(PluginResult.Status.ERROR);
        callbackContext.sendPluginResult(r);
        return true;
      }

      PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT);
      r.setKeepCallback(true);
      callbackContext.sendPluginResult(r);

      return true;
    }
    return false;
  }
  private boolean clearTokenCache(String authority) {
    final AuthenticationContext authContext;
    try {
      authContext = getOrCreateContext(authority);
    } catch (Exception e) {
      callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, e.getMessage()));
      return true;
    }

    authContext.getCache().removeAll();
    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK));
    return true;
  }
Example #10
0
 @Override
 public boolean execute(
     final String action, final JSONArray args, final CallbackContext callbackContext) {
   if (action.equals("get")) {
     cordova
         .getThreadPool()
         .execute(
             new Runnable() {
               @Override
               public void run() {
                 final String version = getPackageVersion();
                 if (version != null) {
                   callbackContext.sendPluginResult(
                       new PluginResult(PluginResult.Status.OK, version));
                 } else {
                   callbackContext.sendPluginResult(
                       new PluginResult(PluginResult.Status.OK, false));
                 }
               }
             });
     return true;
   } else {
     Log.e(LOG_PROV, LOG_NAME + "Error: " + PluginResult.Status.INVALID_ACTION);
     callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION));
     return false;
   }
 }
  public boolean execute(String action, JSONArray args, CallbackContext callbackContext)
      throws JSONException {
    if (action.equals("start")) {
      this.callbackContext = callbackContext;
      if (this.status != Magnetometer.RUNNING) {
        // If not running, then this is an async call, so don't worry about waiting
        // We drop the callback onto our stack, call start, and let start and the sensor callback
        // fire off the callback down the road
        this.start();
      }
    } else if (action.equals("stop")) {
      if (this.status == Magnetometer.RUNNING) {
        this.stop();
      }
    } else {
      // Unsupported action
      return false;
    }

    // Only actions are start and stop. Start is asynchronous, but has no
    // return value. Stop has no return value
    PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT, "");
    result.setKeepCallback(true);
    callbackContext.sendPluginResult(result);
    return true;
  }
  private void getScreenshotAsURI(Bitmap bitmap, int quality) {
    try {
      ByteArrayOutputStream jpeg_data = new ByteArrayOutputStream();

      if (bitmap.compress(CompressFormat.JPEG, quality, jpeg_data)) {
        byte[] code = jpeg_data.toByteArray();
        byte[] output = Base64.encode(code, Base64.NO_WRAP);
        String js_out = new String(output);
        js_out = "data:image/jpeg;base64," + js_out;
        JSONObject jsonRes = new JSONObject();
        jsonRes.put("URI", js_out);
        PluginResult result = new PluginResult(PluginResult.Status.OK, jsonRes);
        mCallbackContext.sendPluginResult(result);

        js_out = null;
        output = null;
        code = null;
      }

      jpeg_data = null;

    } catch (JSONException e) {
      mCallbackContext.error(e.getMessage());

    } catch (Exception e) {
      mCallbackContext.error(e.getMessage());
    }
  }
 @Override
 public boolean execute(String action, CordovaArgs args, final CallbackContext callbackContext)
     throws JSONException {
   this._callbackContext = callbackContext;
   if (ACTION_INIT.equals(action)) {
     return init(args.getString(0), args.getString(1), args.getString(2));
   } else if (ACTION_LOGIN.equals(action)) {
     JSONArray permissions = args.optJSONArray(0);
     return login(permissions, callbackContext);
   } else if (ACTION_SHARE.equals(action)) {
     return shareOrLogin(args.getString(0), args.getString(1));
   } else if (ACTION_FRIENDS_GET.equals(action)) {
     return friendsGet(args.getString(0), args.getString(1), callbackContext);
   } else if (ACTION_FRIENDS_GET_ONLINE.equals(action)) {
     return friendsGetOnline(args.getString(0), args.getString(1), callbackContext);
   } else if (ACTION_STREAM_PUBLISH.equals(action)) {
     // TODO
   } else if (ACTION_USERS_GET_INFO.equals(action)) {
     return usersGetInfo(args.getString(0), args.getString(1), callbackContext);
   } else if (ACTION_CALL_API_METHOD.equals(action)) {
     String method = args.getString(0);
     JSONObject params = args.getJSONObject(1);
     return callApiMethod(method, JsonHelper.toMap(params), callbackContext);
   }
   Log.e(TAG, "Unknown action: " + action);
   _callbackContext.sendPluginResult(
       new PluginResult(PluginResult.Status.ERROR, "Unimplemented method: " + action));
   _callbackContext.error("Unimplemented method: " + action);
   return true;
 }
  private void saveScreenshot(Bitmap bitmap, String format, String fileName, Integer quality) {
    try {
      File folder = new File(Environment.getExternalStorageDirectory(), "Pictures");
      if (!folder.exists()) {
        folder.mkdirs();
      }

      File f = new File(folder, fileName + "." + format);

      FileOutputStream fos = new FileOutputStream(f);
      if (format.equals("png")) {
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
      } else if (format.equals("jpg")) {
        bitmap.compress(Bitmap.CompressFormat.JPEG, quality == null ? 100 : quality, fos);
      }
      JSONObject jsonRes = new JSONObject();
      jsonRes.put("filePath", f.getAbsolutePath());
      PluginResult result = new PluginResult(PluginResult.Status.OK, jsonRes);
      mCallbackContext.sendPluginResult(result);

      scanPhoto(f.getAbsolutePath());
      fos.close();
    } catch (JSONException e) {
      mCallbackContext.error(e.getMessage());

    } catch (IOException e) {
      mCallbackContext.error(e.getMessage());
    }
  }
  @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;
  }
 void sendPluginResult(PluginResult pluginResult) {
   synchronized (this) {
     if (!aborted) {
       callbackContext.sendPluginResult(pluginResult);
     }
   }
 }
  /** Is immersive mode supported? */
  protected boolean isImmersiveModeSupported() {
    boolean supported = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;

    PluginResult res = new PluginResult(PluginResult.Status.OK, supported);
    context.sendPluginResult(res);
    return true;
  }
  /** 插件主入口 */
  @Override
  public boolean execute(String action, final JSONArray args, CallbackContext callbackContext)
      throws JSONException {
    LOG.d(LOG_TAG, "BaiduPush#execute");

    boolean ret = false;

    if ("getCurrentPosition".equalsIgnoreCase(action)) {
      cbCtx = callbackContext;

      PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
      pluginResult.setKeepCallback(true);
      cbCtx.sendPluginResult(pluginResult);

      if (mLocationClient == null) {
        mLocationClient = new LocationClient(this.webView.getContext());
        mLocationClient.registerLocationListener(myListener);

        // 配置定位SDK参数
        initLocation();
      }

      mLocationClient.start();
      ret = true;
    }

    return ret;
  }
  /** Are any of the features of this plugin supported? */
  protected boolean isSupported() {
    boolean supported = Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH;

    PluginResult res = new PluginResult(PluginResult.Status.OK, supported);
    context.sendPluginResult(res);
    return true;
  }
 public static void sendError(String message) {
   PluginResult pluginResult = new PluginResult(PluginResult.Status.ERROR, message);
   pluginResult.setKeepCallback(true);
   if (pushContext != null) {
     pushContext.sendPluginResult(pluginResult);
   }
 }
 public static void sendEvent(JSONObject _json) {
   PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, _json);
   pluginResult.setKeepCallback(true);
   if (pushContext != null) {
     pushContext.sendPluginResult(pluginResult);
   }
 }
  public void onCallStateChanged(int state, String incomingNumber) {
    super.onCallStateChanged(state, incomingNumber);

    if (callbackContext == null) return;

    String msg = "";

    switch (state) {
      case TelephonyManager.CALL_STATE_IDLE:
        msg = "IDLE";
        Log.d(TAG, "IDLE");
        break;

      case TelephonyManager.CALL_STATE_OFFHOOK:
        msg = "OFFHOOK";
        Log.d(TAG, "OFFHOOK");
        break;

      case TelephonyManager.CALL_STATE_RINGING:
        msg = "RINGING";
        Log.d(TAG, "RINGING");
        break;
    }

    PluginResult result = new PluginResult(PluginResult.Status.OK, msg);
    result.setKeepCallback(true);

    callbackContext.sendPluginResult(result);
    Log.d(TAG, "Result: " + result);
  }
Example #23
0
  @Override
  public boolean execute(String action, JSONArray inputs, CallbackContext callbackContext)
      throws JSONException {
    PluginResult result = null;
    if (ACTION_START_SERVER.equals(action)) {
      result = startServer(inputs, callbackContext);

    } else if (ACTION_STOP_SERVER.equals(action)) {
      result = stopServer(inputs, callbackContext);

    } else if (ACTION_GET_URL.equals(action)) {
      result = getURL(inputs, callbackContext);

    } else if (ACTION_GET_LOCAL_PATH.equals(action)) {
      result = getLocalPath(inputs, callbackContext);

    } else if (ACTION_GET_CORDOVAJSROOT.equals(action)) {
      result = getCordovaRoot(inputs, callbackContext);

    } else {
      Log.d(LOGTAG, String.format("Invalid action passed: %s", action));
      result = new PluginResult(Status.INVALID_ACTION);
    }

    if (result != null) callbackContext.sendPluginResult(result);

    return true;
  }
  public void setPushReceiveCallbackChannel(JSONArray data, CallbackContext callbackContext) {
    Log.i(TAG, "setPushReceiveCallbackChannel:" + callbackContext.getCallbackId());

    mJPushReceiveCallback = callbackContext;
    PluginResult dataResult = new PluginResult(PluginResult.Status.OK, "js call init ok");
    dataResult.setKeepCallback(true); // 必要
    mJPushReceiveCallback.sendPluginResult(dataResult);
  }
Example #25
0
 /**
  * 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);
 }
  @Override
  public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {

    if (action.equals("downloadAndOpenFile")) {
      try {
        String fileUrl = args.getString(0);
        JSONObject params = args.getJSONObject(1);
        String fileName =
            params.has("fileName")
                ? params.getString("fileName")
                : fileUrl.substring(fileUrl.lastIndexOf("/") + 1);
        int end = fileUrl.lastIndexOf("/") + 1;
        String encodeFile =
            URLEncoder.encode(fileUrl.substring(fileUrl.lastIndexOf("/") + 1), "UTF-8");
        fileUrl = fileUrl.substring(0, end) + encodeFile;
        String dirName = "";
        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
          dirName = params.has("dirName") ? params.getString("dirName") : "sdcard/download";
        } else {
          dirName = this.cordova.getActivity().getFilesDir().getPath();
        }

        Boolean overwrite = params.has("overwrite") ? params.getBoolean("overwrite") : false;
        Boolean isShowProgress =
            params.has("isShowProgress") ? params.getBoolean("isShowProgress") : true;
        progressInfo = params.has("progressInfo") ? params.getString("progressInfo") : "正在获取数据: ";
        // if (isShowProgress) {
        // showProgressInfo();
        // }
        this.downloadAndOpenFile(fileUrl, dirName, fileName, overwrite, callbackContext);
      } catch (JSONException e) {
        callbackContext.sendPluginResult(
            new PluginResult(PluginResult.Status.ERROR, e.getMessage()));

      } catch (InterruptedException e) {
        callbackContext.sendPluginResult(
            new PluginResult(PluginResult.Status.ERROR, e.getMessage()));
      } catch (UnsupportedEncodingException e) {
        callbackContext.sendPluginResult(
            new PluginResult(PluginResult.Status.ERROR, e.getMessage()));
      }
      return true;
    }
    return false;
  }
  private void sendNoResultPluginResult(CallbackContext callbackContext) {
    // save current callback context
    currentCallbackContext = callbackContext;

    // send no result and keep callback
    PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT);
    result.setKeepCallback(true);
    callbackContext.sendPluginResult(result);
  }
  @Override
  public boolean execute(final String action, JSONArray args, CallbackContext callbackContext)
      throws JSONException {

    JSONObject jo = new JSONObject();
    jo.put("firstName", "John");
    jo.put("lastName", "Doe");

    JSONArray ja = new JSONArray();
    ja.put(jo);

    if (action.equals("getAllPhotos")) {
      PluginResult result = new PluginResult(PluginResult.Status.OK, getAllPhotos());
      result.setKeepCallback(false);
      callbackContext.sendPluginResult(result);
    } else if (action.equals("getPhotoMetadata")) {
      getPhotoMetadata();
    } else if (action.equals("getThumbnails")) {
      PluginResult result = new PluginResult(PluginResult.Status.OK, getThumbnails());
      result.setKeepCallback(false);
      callbackContext.sendPluginResult(result);
    } else if (action.equals("getPhoto")) {
      // final int duration = Toast.LENGTH_SHORT;
      // Shows a toast
      // Log.v(TAG,"LocalAssets received:"+ "getPhotoMetadata");

      // out = args.getJSONArray(0).getString(0);

      // cordova.getActivity().runOnUiThread(new Runnable() {
      //    public void run() {
      //       Toast toast = Toast.makeText(cordova.getActivity().getApplicationContext(), out,
      // duration);
      //       toast.show();
      //   }
      // });

      PluginResult result =
          new PluginResult(
              PluginResult.Status.OK, getPhoto(args.getJSONArray(0).getString(0), args.getInt(1)));
      result.setKeepCallback(false);
      callbackContext.sendPluginResult(result);
    }
    return true;
  }
Example #29
0
 /**
  * Create a new plugin result and send it back to JavaScript
  *
  * @param obj a JSONObject contain event payload information
  * @param status the status code to return to the JavaScript environment
  */
 private void sendUpdate(JSONObject obj, boolean keepCallback, PluginResult.Status status) {
   if (callbackContext != null) {
     PluginResult result = new PluginResult(status, obj);
     result.setKeepCallback(keepCallback);
     callbackContext.sendPluginResult(result);
     if (!keepCallback) {
       callbackContext = null;
     }
   }
 }
Example #30
0
  @Override
  public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
    PluginResult.Status status = PluginResult.Status.OK;
    String result = "";

    try {
      if (action.equals("playVideo")) {
        playVideo(args.getString(0));
      } else {
        status = PluginResult.Status.INVALID_ACTION;
      }
      callbackContext.sendPluginResult(new PluginResult(status, result));
    } catch (JSONException e) {
      callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
    } catch (IOException e) {
      callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION));
    }
    return true;
  }