List of usage examples for org.apache.cordova PluginResult PluginResult
public PluginResult(Status status, List<PluginResult> multipartMessages)
From source file:com.mattrayner.vuforia.VuforiaPlugin.java
public void onRequestPermissionResult(int requestCode, String[] permissions, int[] grantResults) throws JSONException { for (int r : grantResults) { // Is the permission denied for our video request? if (r == PackageManager.PERMISSION_DENIED && requestCode == CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE) { // Send a plugin error this.callback .sendPluginResult(new PluginResult(PluginResult.Status.ERROR, "CAMERA_PERMISSION_ERROR")); return; }//from w w w . ja v a 2 s. c o m } if (requestCode == CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE) execute(ACTION, ARGS, this.callback); // Re-call execute with all the same values as before (will re-check for permissions) }
From source file:com.mattrayner.vuforia.VuforiaPlugin.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { String name;// w w w .j a va 2 s. co m // If we get to this point with no data then we've likely got an error. Or the activity closed because of an error. if (data == null) { name = "ERROR"; } else { name = data.getStringExtra("name"); } Log.d(LOGTAG, "Plugin received '" + name + "' from Vuforia."); // Check which request we're responding to if (requestCode == IMAGE_REC_REQUEST) { JSONObject jsonObj = new JSONObject(); // Check what result code we received switch (resultCode) { case IMAGE_REC_RESULT: // We've received an image (hopefully) // Attempt to build and send a result back to Cordova. try { // Create our status object JSONObject jsonStatus = new JSONObject(); jsonStatus.put("imageFound", true); jsonStatus.put("message", "An image was found."); // Create our result object JSONObject jsonResult = new JSONObject(); jsonResult.put("imageName", name); // Create our response object jsonObj.put("status", jsonStatus); jsonObj.put("result", jsonResult); // Create the plugin result PluginResult result = new PluginResult(PluginResult.Status.OK, jsonObj); // Send a result specifically to our PERSISTANT callback i.e. the callback given to startVuforia. // This allows us to receive other messages from start/stop tracker events without losing this particular callback. persistantVuforiaStartCallback.sendPluginResult(result); } catch (JSONException e) { // We encounter a JSONException Log.d(LOGTAG, "JSON ERROR: " + e); // Send an error to the plugin (so we don't just die quietly) persistantVuforiaStartCallback.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, "JSON ERROR BUILDING IMAGE FOUND RESPONSE: " + e)); } break; case MANUAL_CLOSE_RESULT: // The user has manually closed the plugin. try { // Create our status object JSONObject jsonStatus = new JSONObject(); jsonStatus.put("manuallyClosed", true); jsonStatus.put("message", "User manually closed the plugin."); jsonObj.put("status", jsonStatus); // Send the result back to the persistant callback persistantVuforiaStartCallback .sendPluginResult(new PluginResult(PluginResult.Status.OK, jsonObj)); } catch (JSONException e) { Log.d(LOGTAG, "JSON ERROR: " + e); // Send an error to the plugin (so we don't just die quietly) persistantVuforiaStartCallback.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, "JSON ERROR BUILDING MANUAL CLOSE RESPONSE: " + e)); } break; default: Log.d(LOGTAG, "Error - received unexpected code on Activity close: " + resultCode); } } // Mark Vuforia as closed vuforiaStarted = false; }
From source file:com.mattrayner.vuforia.VuforiaPlugin.java
private void sendSuccessPluginResult() { try {/*from w w w. j av a 2 s. com*/ JSONObject json = new JSONObject(); json.put("success", "true"); callback.sendPluginResult(new PluginResult(PluginResult.Status.OK, json)); } catch (JSONException e) { Log.d(LOGTAG, "JSON ERROR: " + e); } }
From source file:com.mattrayner.vuforia.VuforiaPlugin.java
public static void sendImageFoundUpdate(String imageName) { Log.d(LOGTAG, "Attempting to send an update for image: " + imageName); // Create an object to hold our response JSONObject jsonObj = new JSONObject(); // Try to build a JSON response to send to Cordova try {/*w w w . jav a 2s . co m*/ JSONObject jsonStatus = new JSONObject(); jsonStatus.put("imageFound", true); jsonStatus.put("message", "An image was found."); JSONObject jsonResult = new JSONObject(); jsonResult.put("imageName", imageName); jsonObj.put("status", jsonStatus); jsonObj.put("result", jsonResult); } catch (JSONException e) { Log.d(LOGTAG, "JSON ERROR: " + e); } // Build our response PluginResult result = new PluginResult(PluginResult.Status.OK, jsonObj); result.setKeepCallback(true); // Don't clean up our callback (we intend on sending more messages to it) // Send the result to our PERSISTANT callback persistantVuforiaStartCallback.sendPluginResult(result); }
From source file:com.medicast.plugins.googleanalytics.GoogleAnalyticsPlugin.java
License:Apache License
private void getAppOptOut(CallbackContext callbackContext) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, ga.getAppOptOut())); }
From source file:com.megster.cordova.rfduino.Peripheral.java
License:Apache License
@Override public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { super.onCharacteristicChanged(gatt, characteristic); if (characteristic.getUuid().equals(RECEIVE_CHARACTERISTIC_UUID)) { PluginResult result = new PluginResult(PluginResult.Status.OK, characteristic.getValue()); result.setKeepCallback(true);// w ww . jav a 2 s. c o m onDataCallback.sendPluginResult(result); } }
From source file:com.megster.cordova.rfduino.RFduinoPlugin.java
License:Apache License
@Override public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) { String address = device.getAddress(); if (!peripherals.containsKey(address)) { Peripheral peripheral = new Peripheral(device, rssi, scanRecord); peripherals.put(device.getAddress(), peripheral); if (discoverCallback != null) { PluginResult result = new PluginResult(PluginResult.Status.OK, peripheral.asJSONObject()); result.setKeepCallback(true); discoverCallback.sendPluginResult(result); }/* w w w. j av a 2 s . com*/ } else { // this isn't necessary Peripheral peripheral = peripherals.get(address); peripheral.updateRssi(rssi); } }
From source file:com.microsoft.aad.adal.CordovaAdalPlugin.java
License:Open Source License
private boolean createAsync(String authority, boolean validateAuthority) { try {/*from w ww . ja va2 s .c om*/ getOrCreateContext(authority, validateAuthority); } catch (Exception e) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, e.getMessage())); return true; } callbackContext.success(); return true; }
From source file:com.microsoft.aad.adal.CordovaAdalPlugin.java
License:Open Source License
private boolean acquireTokenAsync(String authority, boolean validateAuthority, String resourceUrl, String clientId, String redirectUrl, String userId, String extraQueryParams) { final AuthenticationContext authContext; try {/* w ww. j a v a 2 s. c o m*/ authContext = getOrCreateContext(authority, validateAuthority); } catch (Exception e) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, e.getMessage())); return true; } if (userId != null) { ITokenCacheStore cache = authContext.getCache(); if (cache instanceof ITokenStoreQuery) { List<TokenCacheItem> tokensForUserId = ((ITokenStoreQuery) cache).getTokensForUser(userId); if (tokensForUserId.size() > 0) { // Try to acquire alias for specified userId userId = tokensForUserId.get(0).getUserInfo().getDisplayableId(); } } } authContext.acquireToken(this.cordova.getActivity(), resourceUrl, clientId, redirectUrl, userId, SHOW_PROMPT_ALWAYS, extraQueryParams, new DefaultAuthenticationCallback(callbackContext)); return true; }
From source file:com.microsoft.aad.adal.CordovaAdalPlugin.java
License:Open Source License
private boolean acquireTokenSilentAsync(String authority, boolean validateAuthority, String resourceUrl, String clientId, String userId) { final AuthenticationContext authContext; try {/*from w ww .j a v a 2 s. c om*/ authContext = getOrCreateContext(authority, validateAuthority); } catch (Exception e) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, e.getMessage())); return true; } authContext.acquireTokenSilent(resourceUrl, clientId, userId, new DefaultAuthenticationCallback(callbackContext)); return true; }