Search in sources :

Example 21 with PluginResult

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);
}
Also used : JSONObject(org.json.JSONObject) PluginResult(org.apache.cordova.PluginResult) JSONException(org.json.JSONException)

Example 22 with PluginResult

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);
    }
}
Also used : PluginResult(org.apache.cordova.PluginResult)

Example 23 with PluginResult

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"));
}
Also used : NativeToJsMessageQueue(org.apache.cordova.NativeToJsMessageQueue) PluginResult(org.apache.cordova.PluginResult) Test(org.junit.Test)

Example 24 with PluginResult

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);
}
Also used : PluginResult(org.apache.cordova.PluginResult)

Example 25 with PluginResult

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);
}
Also used : PluginResult(org.apache.cordova.PluginResult) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray)

Aggregations

PluginResult (org.apache.cordova.PluginResult)45 JSONException (org.json.JSONException)19 JSONObject (org.json.JSONObject)15 IOException (java.io.IOException)6 JSONArray (org.json.JSONArray)6 Uri (android.net.Uri)4 FileNotFoundException (java.io.FileNotFoundException)4 AlertDialog (android.app.AlertDialog)3 DialogInterface (android.content.DialogInterface)3 Intent (android.content.Intent)3 TextView (android.widget.TextView)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 File (java.io.File)3 OutputStream (java.io.OutputStream)3 CallbackContext (org.apache.cordova.CallbackContext)3 CordovaInterface (org.apache.cordova.CordovaInterface)3 CordovaResourceApi (org.apache.cordova.CordovaResourceApi)3 NativeToJsMessageQueue (org.apache.cordova.NativeToJsMessageQueue)3 Test (org.junit.Test)3 SharedPreferences (android.content.SharedPreferences)2