org.apache.cordova.PluginResult.Status Java Examples

The following examples show how to use org.apache.cordova.PluginResult.Status. 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: ZeroConf.java    From cordova-plugin-zeroconf with MIT License 7 votes vote down vote up
public void sendCallback(String action, ServiceInfo service) {
    CallbackContext callbackContext = callbacks.get(service.getType());
    if (callbackContext == null) {
        return;
    }

    JSONObject status = new JSONObject();
    try {
        status.put("action", action);
        status.put("service", jsonifyService(service));

        Log.d(TAG, "Sending result: " + status.toString());

        PluginResult result = new PluginResult(PluginResult.Status.OK, status);
        result.setKeepCallback(true);
        callbackContext.sendPluginResult(result);

    } catch (JSONException e) {
        Log.e(TAG, e.getMessage(), e);
        callbackContext.error("Error: " + e.getMessage());
    }
}
 
Example #2
Source File: InAppServicePlugin.java    From atomic-plugins-inapps with Mozilla Public License 2.0 6 votes vote down vote up
public void consume(CordovaArgs args, final CallbackContext ctx) {
	String productId = args.optString(0);
	if (productId == null) {
		ctx.sendPluginResult(new PluginResult(Status.ERROR, "Invalid argument"));
		return;
	}
	int quantity = args.optInt(1);
	if (quantity < 1) {
		quantity = 1;
	}
	service.consume(productId, quantity, new InAppService.ConsumeCallback() {
		@Override
		public void onComplete(int consumed, Error error) {
			if (error != null) {
				ctx.sendPluginResult(new PluginResult(Status.ERROR, errorToJSON(error)));
			}
			else {
				ctx.sendPluginResult(new PluginResult(Status.OK, consumed));
			}
		}
	});			
}
 
Example #3
Source File: DisconnectionTask.java    From WebSocket-for-Android with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(String rawArgs, CallbackContext ctx) {
    try {
        JSONArray args = new JSONArray(rawArgs);
        int id = Integer.parseInt(args.getString(0), 16);
        int code = args.getInt(1);
        String reason = args.getString(2);
        Connection conn = _map.get(id);

        if (conn != null) {
            if (code > 0) {
                conn.close(code, reason);
            } else {
                conn.close();
            }
        }
    } catch (Exception e) {
        if (!ctx.isFinished()) {
            PluginResult result = new PluginResult(Status.ERROR);
            result.setKeepCallback(true);
            ctx.sendPluginResult(result);
        }
    }
}
 
Example #4
Source File: SendingTask.java    From WebSocket-for-Android with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(String rawArgs, CallbackContext ctx) {
    try {
        String args = new JSONArray(rawArgs).getString(0);
        Connection conn = _map.get(Integer.parseInt(args.substring(0, 8), 16));

        if (conn != null) {
            if (args.charAt(8) == '1') {
                byte[] binary = Base64.decode(args.substring(args.indexOf(',') + 1), Base64.NO_WRAP);
                conn.sendMessage(binary, 0, binary.length);
            } else {
                conn.sendMessage(args.substring(9));
            }
        } else {
        }
    } catch (Exception e) {
        if (!ctx.isFinished()) {
            PluginResult result = new PluginResult(Status.ERROR);
            result.setKeepCallback(true);
            ctx.sendPluginResult(result);
        }
    }
}
 
Example #5
Source File: InAppServicePlugin.java    From atomic-plugins-inapps with Mozilla Public License 2.0 6 votes vote down vote up
public void fetchProducts(CordovaArgs args, final CallbackContext ctx) {

		JSONArray array = args.optJSONArray(0);
		if (array == null) {
			ctx.sendPluginResult(new PluginResult(Status.INVALID_ACTION, "Invalid argument"));
			return;
		}
		ArrayList<String> productIds = new ArrayList<String>();
		for (int i = 0; i < array.length(); ++i) {
			productIds.add(array.optString(i, "empty"));
		}
		service.fetchProducts(productIds, new InAppService.FetchCallback() {
			
			@Override
			public void onComplete(final List<InAppProduct> products, Error error) {
				if (error != null) {
					ctx.sendPluginResult(new PluginResult(Status.ERROR, errorToJSON(error)));
				}
				else {
					ctx.sendPluginResult(new PluginResult(Status.OK, productsToJSON(products)));
				}
			}
		});
	}
 
Example #6
Source File: InAppServicePlugin.java    From atomic-plugins-inapps with Mozilla Public License 2.0 6 votes vote down vote up
public void initialize(CordovaArgs args, final CallbackContext ctx) throws JSONException {
	service.addPurchaseObserver(this);

	service.init(new InAppService.InitCompletion() {
		@Override
		public void onInit(Error error) {
			JSONObject data = new JSONObject();
			try {
				data.put("products", InAppServicePlugin.this.productsToJSON(service.getProducts()));
				data.put("canPurchase", service.canPurchase());
				if (error != null) {
					data.put("error", errorToJSON(error));
				}
			}
			catch (JSONException e) {
				e.printStackTrace();
			}

			ctx.sendPluginResult(new PluginResult(Status.OK, data));
		}

	});


}
 
Example #7
Source File: TwilioVoicePlugin.java    From cordova-plugin-twiliovoicesdk with MIT License 6 votes vote down vote up
private void javascriptCallback(String event, JSONObject arguments,
                                CallbackContext callbackContext) {
    if (callbackContext == null) {
        return;
    }
    JSONObject options = new JSONObject();
    try {
        options.putOpt("callback", event);
        options.putOpt("arguments", arguments);
    } catch (JSONException e) {
        callbackContext.sendPluginResult(new PluginResult(
                PluginResult.Status.JSON_EXCEPTION));
        return;
    }
    PluginResult result = new PluginResult(Status.OK, options);
    result.setKeepCallback(true);
    callbackContext.sendPluginResult(result);

}
 
Example #8
Source File: WifiAdmin.java    From cordova-plugin-wifi with MIT License 6 votes vote down vote up
private PluginResult executeEnableWifi(JSONArray inputs, CallbackContext callbackContext) {
  	Log.w(LOGTAG, "executeEnableWifi");

Context context = cordova.getActivity().getApplicationContext();
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);

boolean toEnable = true;
try {
	toEnable = inputs.getBoolean( 0 );
} catch (JSONException e) {
      Log.w(LOGTAG, String.format("Got JSON Exception: %s", e.getMessage()));
      return new PluginResult(Status.JSON_EXCEPTION);
}
      
wifiManager.setWifiEnabled( toEnable );
callbackContext.success();

  	return null;
  }
 
Example #9
Source File: InAppServicePlugin.java    From atomic-plugins-inapps with Mozilla Public License 2.0 6 votes vote down vote up
public void setValidationHandler(CordovaArgs args, final CallbackContext ctx) {
	boolean noValidation = args.optBoolean(0);
	if (noValidation) {
		service.setValidationHandler(null);
		return;
	}
	service.setValidationHandler(new InAppService.ValidationHandler() {
		
		@Override
		public void onValidate(String receipt, String productId, ValidationCompletion completion) {
			
			int completionId = validationIndex++;
			validationCompletions.put(completionId, completion);
			JSONArray array = new JSONArray();
			array.put(receipt);
			array.put(productId);
			array.put(completionId);
			PluginResult result = new PluginResult(Status.OK, array);		
			result.setKeepCallback(true);
			ctx.sendPluginResult(result);
		}
	});
}
 
Example #10
Source File: InAppServicePlugin.java    From atomic-plugins-inapps with Mozilla Public License 2.0 5 votes vote down vote up
public void restorePurchases(CordovaArgs args, final CallbackContext ctx) {
	service.restorePurchases(new InAppService.RestoreCallback() {
		@Override
		public void onComplete(Error error) {
			if (error != null) {
				ctx.sendPluginResult(new PluginResult(Status.ERROR, errorToJSON(error)));
			}
			else {
				ctx.sendPluginResult(new PluginResult(Status.OK));
			}
		}
	});
}
 
Example #11
Source File: InAppServicePlugin.java    From atomic-plugins-inapps with Mozilla Public License 2.0 5 votes vote down vote up
public void productforId(CordovaArgs args, CallbackContext ctx) {
	String productId = args.optString(0);
	InAppProduct product = null;
	if (productId != null) {
		product = service.productForId(productId);
	}
	if (product!= null) {
		ctx.sendPluginResult(new PluginResult(Status.OK, product.toJSON()));	
	}
	else {
		ctx.sendPluginResult(new PluginResult(Status.OK));
	}
}
 
Example #12
Source File: InAppServicePlugin.java    From atomic-plugins-inapps with Mozilla Public License 2.0 5 votes vote down vote up
@Override
  public void onPurchaseStart(InAppService sender, String productId)  {
if (listenerCtx != null) {
	JSONArray data = new JSONArray();
	data.put("start");
	data.put(productId);
	PluginResult result = new PluginResult(Status.OK, data);
	result.setKeepCallback(true);
	listenerCtx.sendPluginResult(result);
}
  }
 
Example #13
Source File: InAppServicePlugin.java    From atomic-plugins-inapps with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void onPurchaseFail(InAppService sender, String productId, Error error) {
	if (listenerCtx != null) {
		JSONArray data = new JSONArray();
		data.put("error");
		data.put(productId);
		data.put(this.errorToJSON(error));
		PluginResult result = new PluginResult(Status.OK, data);
		result.setKeepCallback(true);
		listenerCtx.sendPluginResult(result);
	}
   }
 
Example #14
Source File: InAppServicePlugin.java    From atomic-plugins-inapps with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void onPurchaseComplete(InAppService sender, InAppPurchase purchase){
	if (listenerCtx != null) {
		JSONArray data = new JSONArray();
		data.put("complete");
		data.put(purchase.toJSON());
		PluginResult result = new PluginResult(Status.OK, data);
		result.setKeepCallback(true);
		listenerCtx.sendPluginResult(result);
	}
   }
 
Example #15
Source File: WifiAdmin.java    From cordova-plugin-wifi with MIT License 5 votes vote down vote up
private PluginResult executeConnectWifi(JSONArray inputs, CallbackContext callbackContext) {
  	Log.w(LOGTAG, "executeConnectWifi");

boolean toEnable = true;
try {
	toEnable = inputs.getBoolean( 0 );
} catch (JSONException e) {
      Log.w(LOGTAG, String.format("Got JSON Exception: %s", e.getMessage()));
      return new PluginResult(Status.JSON_EXCEPTION);
}

return null;
  }
 
Example #16
Source File: WifiAdmin.java    From cordova-plugin-wifi with MIT License 5 votes vote down vote up
private PluginResult executeEnableWifiAP(JSONArray inputs, CallbackContext callbackContext) {
  	Log.w(LOGTAG, "executeEnableWifiAP");

boolean toEnable = true;
try {
	toEnable = inputs.getBoolean( 0 );
} catch (JSONException e) {
      Log.w(LOGTAG, String.format("Got JSON Exception: %s", e.getMessage()));
      return new PluginResult(Status.JSON_EXCEPTION);
}

return null;
  }
 
Example #17
Source File: WifiAdmin.java    From cordova-plugin-wifi with MIT License 5 votes vote down vote up
private PluginResult executeEnableWifiLock(JSONArray inputs, CallbackContext callbackContext) {
  	Log.w(LOGTAG, "executeEnableWifiLock");

boolean toEnable = true;
try {
	toEnable = inputs.getBoolean( 0 );
} catch (JSONException e) {
      Log.w(LOGTAG, String.format("Got JSON Exception: %s", e.getMessage()));
      return new PluginResult(Status.JSON_EXCEPTION);
}

Context context = cordova.getActivity().getApplicationContext();
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);

if(wifiLock == null) {
	wifiLock = wifiManager.createWifiLock("Test");
}

if(wifiLock != null) {
	if(toEnable) {
		wifiLock.acquire();
	} else {
        if(wifiLock.isHeld()) {
        	wifiLock.release();
        }
	}
}

callbackContext.success();

  	return null;
  }
 
Example #18
Source File: WebSocketGenerator.java    From WebSocket-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Send plugin result.
 *
 * @param callbackString
 * @param keepCallback
 */
private void sendCallback(String callbackString, boolean keepCallback) {
    if (!_ctx.isFinished()) {
        PluginResult result = new PluginResult(Status.OK, callbackString);
        result.setKeepCallback(keepCallback);
        _ctx.sendPluginResult(result);
    }
}
 
Example #19
Source File: BackgroundModeExt.java    From cordova-plugin-background-mode with Apache License 2.0 5 votes vote down vote up
/**
 * Invokes the callback with information if the screen is on.
 *
 * @param callback The callback to invoke.
 */
@SuppressWarnings("deprecation")
private void isDimmed (CallbackContext callback)
{
    boolean status   = isDimmed();
    PluginResult res = new PluginResult(Status.OK, status);

    callback.sendPluginResult(res);
}
 
Example #20
Source File: TwilioVoicePlugin.java    From cordova-plugin-twiliovoicesdk with MIT License 5 votes vote down vote up
public void onRequestPermissionResult(int requestCode, String[] permissions,
                                      int[] grantResults) throws JSONException {
    for (int r : grantResults) {
        if (r == PackageManager.PERMISSION_DENIED) {
            mInitCallbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, "Permission denied"));
            return;
        }
    }
}
 
Example #21
Source File: TwilioVoicePlugin.java    From cordova-plugin-twiliovoicesdk with MIT License 5 votes vote down vote up
private void rejectCallInvite(JSONArray arguments, final CallbackContext callbackContext) {
    if (mCallInvite == null) {
        callbackContext.sendPluginResult(new PluginResult(
                PluginResult.Status.ERROR));
        return;
    }
    cordova.getThreadPool().execute(new Runnable() {
        public void run() {
            mCallInvite.reject(cordova.getActivity());
            callbackContext.success();
        }
    });
}
 
Example #22
Source File: TwilioVoicePlugin.java    From cordova-plugin-twiliovoicesdk with MIT License 5 votes vote down vote up
private void disconnect(JSONArray arguments, final CallbackContext callbackContext) {
    if (mCall == null) {
        callbackContext.sendPluginResult(new PluginResult(
                PluginResult.Status.ERROR));
        return;
    }
    cordova.getThreadPool().execute(new Runnable() {
        public void run() {
            mCall.disconnect();
            callbackContext.success();
        }
    });
}
 
Example #23
Source File: TwilioVoicePlugin.java    From cordova-plugin-twiliovoicesdk with MIT License 5 votes vote down vote up
private void sendDigits(final JSONArray arguments,
                        final CallbackContext callbackContext) {
    if (arguments == null || arguments.length() < 1 || mCall == null) {
        callbackContext.sendPluginResult(new PluginResult(
                PluginResult.Status.ERROR));
        return;
    }
    cordova.getThreadPool().execute(new Runnable() {
        public void run() {
            mCall.sendDigits(arguments.optString(0));
            callbackContext.success();
        }
    });

}
 
Example #24
Source File: TwilioVoicePlugin.java    From cordova-plugin-twiliovoicesdk with MIT License 5 votes vote down vote up
private void muteCall(final CallbackContext callbackContext) {
    if (mCall == null) {
        callbackContext.sendPluginResult(new PluginResult(
                PluginResult.Status.ERROR));
        return;
    }
    cordova.getThreadPool().execute(new Runnable() {
        public void run() {
            mCall.mute(true);
            callbackContext.success();
        }
    });
}
 
Example #25
Source File: TwilioVoicePlugin.java    From cordova-plugin-twiliovoicesdk with MIT License 5 votes vote down vote up
private void unmuteCall(final CallbackContext callbackContext) {
    if (mCall == null) {
        callbackContext.sendPluginResult(new PluginResult(
                PluginResult.Status.ERROR));
        return;
    }
    cordova.getThreadPool().execute(new Runnable() {
        public void run() {
            mCall.mute(false);
            callbackContext.success();
        }
    });
}
 
Example #26
Source File: TwilioVoicePlugin.java    From cordova-plugin-twiliovoicesdk with MIT License 5 votes vote down vote up
private void isCallMuted(CallbackContext callbackContext) {
    if (mCall == null) {
        callbackContext.sendPluginResult(new PluginResult(
                PluginResult.Status.OK, false));
        return;
    }
    PluginResult result = new PluginResult(PluginResult.Status.OK, mCall.isMuted());
    callbackContext.sendPluginResult(result);
}
 
Example #27
Source File: TwilioVoicePlugin.java    From cordova-plugin-twiliovoicesdk with MIT License 5 votes vote down vote up
private void callStatus(CallbackContext callbackContext) {
    if (mCall == null) {
        callbackContext.sendPluginResult(new PluginResult(
                PluginResult.Status.ERROR));
        return;
    }
    String state = getCallState(mCall.getState());
    if (state == null) {
        state = "";
    }
    PluginResult result = new PluginResult(PluginResult.Status.OK, state);
    callbackContext.sendPluginResult(result);
}
 
Example #28
Source File: TwilioVoicePlugin.java    From cordova-plugin-twiliovoicesdk with MIT License 5 votes vote down vote up
private void javascriptErrorback(int errorCode, String errorMessage, CallbackContext callbackContext) {
    JSONObject object = new JSONObject();
    try {
        object.putOpt("message", errorMessage);
    } catch (JSONException e) {
        callbackContext.sendPluginResult(new PluginResult(
                PluginResult.Status.JSON_EXCEPTION));
        return;
    }
    PluginResult result = new PluginResult(Status.ERROR, object);
    result.setKeepCallback(true);
    callbackContext.sendPluginResult(result);
}
 
Example #29
Source File: Utils.java    From cordova-plugin-iroot with MIT License 5 votes vote down vote up
/**
 * Helper function that logs the error and then calls the error callback.
 */
public static PluginResult getPluginResultError(final String from, final Throwable e) {
    String message = String.format("[%s] Error: %s", from, e.getMessage());

    LOG.e(Constants.LOG_TAG, message, e);

    return new PluginResult(Status.ERROR, message);
}
 
Example #30
Source File: WebSocketGenerator.java    From IoTgo_Android_App with MIT License 5 votes vote down vote up
/**
 * Send plugin result.
 *
 * @param callbackString
 * @param keepCallback
 */
private void sendCallback(String callbackString, boolean keepCallback) {
    if (!_ctx.isFinished()) {
        PluginResult result = new PluginResult(Status.OK, callbackString);
        result.setKeepCallback(keepCallback);
        _ctx.sendPluginResult(result);
    }
}