use of org.apache.cordova.PluginResult in project jpHolo by teusink.
the class AccelListener method fail.
// Sends an error back to JS
private void fail(int code, String message) {
// Error object
JSONObject errorObj = new JSONObject();
try {
errorObj.put("code", code);
errorObj.put("message", message);
} catch (JSONException e) {
e.printStackTrace();
}
PluginResult err = new PluginResult(PluginResult.Status.ERROR, errorObj);
err.setKeepCallback(true);
callbackContext.sendPluginResult(err);
}
use of org.apache.cordova.PluginResult in project jpHolo by teusink.
the class BatteryListener method sendUpdate.
/**
* Create a new plugin result and send it back to JavaScript
*
* @param connection the network info to set as navigator.connection
*/
private void sendUpdate(JSONObject info, boolean keepCallback) {
if (this.batteryCallbackContext != null) {
PluginResult result = new PluginResult(PluginResult.Status.OK, info);
result.setKeepCallback(keepCallback);
this.batteryCallbackContext.sendPluginResult(result);
}
}
use of org.apache.cordova.PluginResult in project cordova-android by apache.
the class NativeToJsMessageQueueTest method testBasicPopAndEncodeAsJs.
//This test is for the evalBridge, which directly calls cordova.callbackFromNative, skipping
//platform specific NativeToJs code
@Test
public void testBasicPopAndEncodeAsJs() {
NativeToJsMessageQueue.BridgeMode bridge;
bridge = new NativeToJsMessageQueue.NoOpBridgeMode();
queue.addBridgeMode(bridge);
queue.setBridgeMode(0);
PluginResult result = new PluginResult(PluginResult.Status.OK);
queue.addPluginResult(result, TEST_CALLBACK_ID);
assertFalse(queue.isEmpty());
String resultString = queue.popAndEncodeAsJs();
assertTrue(resultString.startsWith("cordova.callbackFromNative"));
}
use of org.apache.cordova.PluginResult in project cordova-plugin-local-notifications by katzer.
the class LocalNotification method isScheduled.
/**
* If a notification with an ID is scheduled.
*
* @param id
* Notification ID
* @param command
* The callback context used when calling back into JavaScript.
*/
private void isScheduled(int id, CallbackContext command) {
boolean exist = getNotificationMgr().exist(id, Notification.Type.SCHEDULED);
PluginResult result = new PluginResult(PluginResult.Status.OK, exist);
command.sendPluginResult(result);
}
use of org.apache.cordova.PluginResult in project cordova-plugin-local-notifications by katzer.
the class LocalNotification method getOptions.
/**
* Options from local notification.
*
* @param id
* Set of local notification IDs
* @param type
* The local notification life cycle type
* @param command
* The callback context used when calling back into JavaScript.
*/
private void getOptions(String id, Notification.Type type, CallbackContext command) {
JSONArray ids = new JSONArray().put(id);
PluginResult result;
List<JSONObject> options = getNotificationMgr().getOptionsBy(type, toList(ids));
if (options.isEmpty()) {
// Status.NO_RESULT led to no callback invocation :(
// Status.OK led to no NPE and crash
result = new PluginResult(PluginResult.Status.NO_RESULT);
} else {
result = new PluginResult(PluginResult.Status.OK, options.get(0));
}
command.sendPluginResult(result);
}
Aggregations