Java Code Examples for org.apache.cordova.CallbackContext#success()

The following examples show how to use org.apache.cordova.CallbackContext#success() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Device.java    From AvI with MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example 2
Source File: FileTransfer.java    From reader with MIT License 6 votes vote down vote up
@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;
}
 
Example 3
Source File: FirebaseMessagingPlugin.java    From cordova-plugin-firebase-messaging with MIT License 6 votes vote down vote up
@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()));
    }
}
 
Example 4
Source File: UID.java    From cordova-plugin-uid with MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example 5
Source File: CodePush.java    From reacteu-app with MIT License 6 votes vote down vote up
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;
}
 
Example 6
Source File: FirebaseMessagingPlugin.java    From cordova-plugin-firebase-messaging with MIT License 6 votes vote down vote up
@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);
}
 
Example 7
Source File: FileTransfer.java    From reacteu-app with MIT License 6 votes vote down vote up
@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;
}
 
Example 8
Source File: TTS.java    From reader with MIT License 5 votes vote down vote up
@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;
}
 
Example 9
Source File: CameraPreview.java    From cordova-plugin-camera-preview with MIT License 5 votes vote down vote up
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;
}
 
Example 10
Source File: GeolocationPlugin.java    From cordova-plugin-baidu-geolocation with MIT License 5 votes vote down vote up
private boolean clearWatch(int watchId, CallbackContext callback) {
  Log.i(TAG, "停止监听");
  BDGeolocation geolocation = store.get(watchId);
  store.remove(watchId);
  geolocation.clearWatch();
  callback.success();
  return true;
}
 
Example 11
Source File: AppAvailability.java    From reader with MIT License 5 votes vote down vote up
private void checkAvailability(String uri, CallbackContext callbackContext) {
    if(appInstalled(uri)) {
        callbackContext.success();
    }
    else {
        callbackContext.error("");
    }
}
 
Example 12
Source File: LocalNotification.java    From showCaseCordova with Apache License 2.0 5 votes vote down vote up
/**
 * 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));
}
 
Example 13
Source File: CheckGPS.java    From cordova-plugin-fastrde-checkgps with MIT License 5 votes vote down vote up
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);
}
}
 
Example 14
Source File: CodePush.java    From reacteu-app with MIT License 5 votes vote down vote up
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;
}
 
Example 15
Source File: WizPurchase.java    From cordova-plugin-wizpurchase with MIT License 5 votes vote down vote up
@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;
}
 
Example 16
Source File: CameraPreview.java    From cordova-plugin-camera-preview with MIT License 5 votes vote down vote up
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;
}
 
Example 17
Source File: CodePush.java    From reacteu-app with MIT License 5 votes vote down vote up
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;
}
 
Example 18
Source File: CameraPreview.java    From cordova-plugin-camera-preview with MIT License 5 votes vote down vote up
private boolean switchCamera(CallbackContext callbackContext) {
  if(this.hasView(callbackContext) == false){
    return true;
  }

  fragment.switchCamera();

  callbackContext.success();

  return true;
}
 
Example 19
Source File: BluetoothPrinter.java    From Cordova-Plugin-BTPrinter with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 20
Source File: LocalNotification.java    From showCaseCordova with Apache License 2.0 2 votes vote down vote up
/**
 * 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));
}