org.apache.cordova.CallbackContext#success ( )源码实例Demo

下面列出了org.apache.cordova.CallbackContext#success ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: reader   文件: FileTransfer.java
@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;
    }
    return false;
}
 
源代码2 项目: AvI   文件: Device.java
/**
 * 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 if not.
 */
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    if ("getDeviceInfo".equals(action)) {
        JSONObject r = new JSONObject();
        r.put("uuid", Device.uuid);
        r.put("version", this.getOSVersion());
        r.put("platform", this.getPlatform());
        r.put("model", this.getModel());
        r.put("manufacturer", this.getManufacturer());
     r.put("isVirtual", this.isVirtual());
        r.put("serial", this.getSerialNumber());
        callbackContext.success(r);
    }
    else {
        return false;
    }
    return true;
}
 
源代码3 项目: cordova-plugin-uid   文件: UID.java
/**
 * 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 if not.
 */
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
	if (action.equals("getUID")) {
		JSONObject r = new JSONObject();
		r.put("UUID", UID.uuid);
		r.put("IMEI", UID.imei);
		r.put("IMSI", UID.imsi);
		r.put("ICCID", UID.iccid);
		r.put("MAC", UID.mac);
		callbackContext.success(r);
	} else {
		return false;
	}
	return true;
}
 
源代码4 项目: reacteu-app   文件: CodePush.java
private boolean execIsFirstRun(CordovaArgs args, CallbackContext callbackContext) {
    try {
        boolean isFirstRun = false;
        String packageHash = args.getString(0);
        CodePushPackageMetadata currentPackageMetadata = codePushPackageManager.getCurrentPackageMetadata();
        if (null != currentPackageMetadata) {
            /* This is the first run for a package if we just updated, and the current package hash matches the one provided. */
            isFirstRun = (null != packageHash
                    && !packageHash.isEmpty()
                    && packageHash.equals(currentPackageMetadata.packageHash)
                    && didUpdate);
        }
        callbackContext.success(isFirstRun ? 1 : 0);
    } catch (JSONException e) {
        callbackContext.error("Invalid package hash. " + e.getMessage());
    }
    return true;
}
 
源代码5 项目: reacteu-app   文件: FileTransfer.java
@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;
}
 
@CordovaMethod
private void listChannels(CallbackContext callbackContext) throws JSONException {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
        throw new UnsupportedOperationException("Notification channels are not supported");
    }

    List<NotificationChannel> channels = notificationManager.getNotificationChannels();
    JSONArray result = new JSONArray();
    for (NotificationChannel channel : channels) {
        result.put(new JSONObject()
            .put("id", channel.getId())
            .put("name", channel.getName())
            .put("description", channel.getDescription()));
    }

    callbackContext.success(result);
}
 
@CordovaMethod
private void findChannel(String channelId, CallbackContext callbackContext) throws JSONException {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
        throw new UnsupportedOperationException("Notification channels are not supported");
    }

    NotificationChannel channel = notificationManager.getNotificationChannel(channelId);
    if (channel == null) {
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, (String)null));
    } else {
        callbackContext.success(new JSONObject()
            .put("id", channel.getId())
            .put("name", channel.getName())
            .put("description", channel.getDescription()));
    }
}
 
private boolean switchCamera(CallbackContext callbackContext) {
  if(this.hasView(callbackContext) == false){
    return true;
  }

  fragment.switchCamera();

  callbackContext.success();

  return true;
}
 
源代码9 项目: reacteu-app   文件: CodePush.java
private boolean execIsFailedUpdate(CordovaArgs args, CallbackContext callbackContext) {
    try {
        final String packageHash = args.getString(0);
        boolean isFailedUpdate = this.codePushPackageManager.isFailedUpdate(packageHash);
        callbackContext.success(isFailedUpdate ? 1 : 0);
    } catch (JSONException e) {
        callbackContext.error("Could not read the package hash: " + e.getMessage());
    }
    return true;
}
 
private boolean setWhiteBalanceMode(String whiteBalanceMode, CallbackContext callbackContext) {
  if(this.hasCamera(callbackContext) == false){
    return true;
  }

  Camera camera = fragment.getCamera();
  Camera.Parameters params = camera.getParameters();

  if (whiteBalanceMode.equals("lock")) {
    if (camera.getParameters().isAutoWhiteBalanceLockSupported()) {
      params.setAutoWhiteBalanceLock(true);
      fragment.setCameraParameters(params);
      callbackContext.success();
    } else {
      callbackContext.error("White balance lock not supported");
    }
  } else if (whiteBalanceMode.equals("auto") ||
             whiteBalanceMode.equals("incandescent") ||
             whiteBalanceMode.equals("cloudy-daylight") ||
             whiteBalanceMode.equals("daylight") ||
             whiteBalanceMode.equals("fluorescent") ||
             whiteBalanceMode.equals("shade") ||
             whiteBalanceMode.equals("twilight") ||
             whiteBalanceMode.equals("warm-fluorescent")) {
    params.setWhiteBalance(whiteBalanceMode);
    fragment.setCameraParameters(params);
    callbackContext.success();
  } else {
    callbackContext.error("White balance parameter not supported");
  }

  return true;
}
 
源代码11 项目: cordova-plugin-wizpurchase   文件: WizPurchase.java
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
	Log.d(TAG, "Plugin execute called with action: " + action);

	// Reset all handlers
	mRestoreAllCbContext     = null;
	mProductDetailCbContext  = null;
	mMakePurchaseCbContext   = null;
	mGetPendingCbContext     = null;
	mFinishPurchaseCbContext = null;

	if (action.equalsIgnoreCase("getPendingPurchases")) {
		getPendingPurchases(callbackContext);
		return true;
	} else if (action.equalsIgnoreCase("restoreAllPurchases")) {
		restoreAllPurchases(callbackContext);
		return true;
	} else if (action.equalsIgnoreCase("getProductDetails")) {
		getProductsDetails(args, callbackContext);
		return true;
	} else if (action.equalsIgnoreCase("makePurchase")) {
		makePurchase(args, callbackContext);
		return true;
	} else if (action.equalsIgnoreCase("finishPurchase")) {
		finishPurchase(args, callbackContext);
		return true;
	} else if (action.equalsIgnoreCase("refreshReceipt")) {
		callbackContext.success();
		return true;
	} else if (action.equalsIgnoreCase("setApplicationUsername")) {
		callbackContext.success();
		return true;
	}
	return false;
}
 
源代码12 项目: reacteu-app   文件: CodePush.java
private boolean execIsPendingUpdate(CordovaArgs args, CallbackContext callbackContext) {
    try {
        InstallOptions pendingInstall = this.codePushPackageManager.getPendingInstall();
        callbackContext.success((pendingInstall != null) ? 1 : 0);
    } catch (Exception e) {
        callbackContext.error("An error occurred. " + e.getMessage());
    }
    return true;
}
 
源代码13 项目: cordova-plugin-fastrde-checkgps   文件: CheckGPS.java
private void check(CallbackContext callbackContext){
Context context = this.cordova.getActivity().getApplicationContext();
  final LocationManager manager = (LocationManager) context.getSystemService( Context.LOCATION_SERVICE );
  if ( manager.isProviderEnabled( LocationManager.GPS_PROVIDER ) ) {
	callbackContext.success();
  }else{
	callbackContext.error(0);
}
}
 
源代码14 项目: showCaseCordova   文件: LocalNotification.java
/**
 * Set of IDs from all scheduled notifications.
 *
 * @param command
 *      The callback context used when calling back into JavaScript.
 */
private void getScheduledIds (CallbackContext command) {
    List<Integer> ids = getNotificationMgr().getIdsByType(
            Notification.Type.SCHEDULED);

    command.success(new JSONArray(ids));
}
 
源代码15 项目: reader   文件: AppAvailability.java
private void checkAvailability(String uri, CallbackContext callbackContext) {
    if(appInstalled(uri)) {
        callbackContext.success();
    }
    else {
        callbackContext.error("");
    }
}
 
private boolean clearWatch(int watchId, CallbackContext callback) {
  Log.i(TAG, "停止监听");
  BDGeolocation geolocation = store.get(watchId);
  store.remove(watchId);
  geolocation.clearWatch();
  callback.success();
  return true;
}
 
private boolean getExposureCompensationRange(CallbackContext callbackContext) {
  if(this.hasCamera(callbackContext) == false){
    return true;
  }

  Camera camera = fragment.getCamera();
  Camera.Parameters params = camera.getParameters();

  int minExposureCompensation = camera.getParameters().getMinExposureCompensation();
  int maxExposureCompensation = camera.getParameters().getMaxExposureCompensation();

  if (minExposureCompensation == 0 && maxExposureCompensation == 0) {
    callbackContext.error("Exposure corection not supported");
  } else {
    JSONObject jsonExposureRange = new JSONObject();
    try {
      jsonExposureRange.put("min", new Integer(minExposureCompensation));
      jsonExposureRange.put("max", new Integer(maxExposureCompensation));
    }
    catch(JSONException e){
      e.printStackTrace();
    }
    callbackContext.success(jsonExposureRange);
  }

  return true;
}
 
源代码18 项目: reader   文件: TTS.java
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext)
        throws JSONException {
    if (action.equals("speak")) {       
        speak(args, callbackContext);
    } else if (action.equals("stop")) {
        tts.stop();
    }
    else if (action.equals("getDefaultEngine")) {
    	callbackContext.success(tts.getDefaultEngine());
    }else {
        return false;
    }
    return true;
}
 
boolean printBase64(CallbackContext callbackContext, String msg, Integer align) throws IOException {
    try {

        final String encodedString = msg;
        final String pureBase64Encoded = encodedString.substring(encodedString.indexOf(",") + 1);
        final byte[] decodedBytes = Base64.decode(pureBase64Encoded, Base64.DEFAULT);

        Bitmap decodedBitmap = BitmapFactory.decodeByteArray(decodedBytes, 0, decodedBytes.length);

        bitmap = decodedBitmap;
        int mWidth = bitmap.getWidth();
        int mHeight = bitmap.getHeight();

        bitmap = resizeImage(bitmap, 48 * 8, mHeight);

        byte[] bt = decodeBitmapBase64(bitmap);

        // not work
        Log.d(LOG_TAG, "SWITCH ALIGN BASE64 -> " + align);
        switch (align) {
        case 0:
            mmOutputStream.write(ESC_ALIGN_LEFT);
            mmOutputStream.write(bt);
            break;
        case 1:
            mmOutputStream.write(ESC_ALIGN_CENTER);
            mmOutputStream.write(bt);
            break;
        case 2:
            mmOutputStream.write(ESC_ALIGN_RIGHT);
            mmOutputStream.write(bt);
            break;
        }
        // tell the user data were sent
        Log.d(LOG_TAG, "PRINT BASE64 SEND");
        callbackContext.success("PRINT BASE64 SEND");
        return true;

    } catch (Exception e) {
        String errMsg = e.getMessage();
        Log.e(LOG_TAG, errMsg);
        e.printStackTrace();
        callbackContext.error(errMsg);
    }
    return false;
}
 
源代码20 项目: showCaseCordova   文件: LocalNotification.java
/**
 * Set of IDs from all existent notifications.
 *
 * @param command
 *      The callback context used when calling back into JavaScript.
 */
private void getAllIds (CallbackContext command) {
    List<Integer> ids = getNotificationMgr().getIds();

    command.success(new JSONArray(ids));
}