Search in sources :

Example 16 with PluginResult

use of org.apache.cordova.PluginResult in project TelephoneNumberPlugin by macdonst.

the class TelephoneNumber method execute.

public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
    if (action.equals("get")) {
        TelephonyManager telephonyManager = (TelephonyManager) this.cordova.getActivity().getSystemService(Context.TELEPHONY_SERVICE);
        String result = telephonyManager.getLine1Number();
        if (result != null) {
            callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result));
            return true;
        }
    }
    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR));
    return false;
}
Also used : PluginResult(org.apache.cordova.PluginResult) TelephonyManager(android.telephony.TelephonyManager)

Example 17 with PluginResult

use of org.apache.cordova.PluginResult in project cordova-android by apache.

the class NativeToJsMessageQueueTest method testJsonPopAndEncodeAsJs.

//This test is for the evalBridge, which directly calls cordova.callbackFromNative, skipping
//platform specific NativeToJs code
@Test
public void testJsonPopAndEncodeAsJs() {
    NativeToJsMessageQueue.BridgeMode bridge;
    bridge = new NativeToJsMessageQueue.NoOpBridgeMode();
    queue.addBridgeMode(bridge);
    queue.setBridgeMode(0);
    JSONObject object = new JSONObject();
    try {
        object.put("test", "value");
    } catch (JSONException e) {
        e.printStackTrace();
    }
    PluginResult result = new PluginResult(PluginResult.Status.OK, object);
    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) JSONObject(org.json.JSONObject) PluginResult(org.apache.cordova.PluginResult) JSONException(org.json.JSONException) Test(org.junit.Test)

Example 18 with PluginResult

use of org.apache.cordova.PluginResult in project cordova-android by apache.

the class NativeToJsMessageQueueTest method testStringPopAndEncodeAsJs.

//This test is for the evalBridge, which directly calls cordova.callbackFromNative, skipping
//platform specific NativeToJs code
@Test
public void testStringPopAndEncodeAsJs() {
    NativeToJsMessageQueue.BridgeMode bridge;
    bridge = new NativeToJsMessageQueue.NoOpBridgeMode();
    queue.addBridgeMode(bridge);
    queue.setBridgeMode(0);
    PluginResult result = new PluginResult(PluginResult.Status.OK, "String Plugin Result");
    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 19 with PluginResult

use of org.apache.cordova.PluginResult in project cordova-android by apache.

the class NativeToJsMessageQueueTest method testPopAndEncode.

//This test is for the undocumented encoding system setup for the bridge
//TODO: Document how the non-Javascript bridges are supposed to work
@Test
public void testPopAndEncode() {
    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.popAndEncode(false);
    String[] results = resultString.split(" ");
    assertEquals(TEST_CALLBACK_ID, results[2]);
}
Also used : NativeToJsMessageQueue(org.apache.cordova.NativeToJsMessageQueue) PluginResult(org.apache.cordova.PluginResult) Test(org.junit.Test)

Example 20 with PluginResult

use of org.apache.cordova.PluginResult in project cordova-plugin-local-notifications by katzer.

the class LocalNotification method isPresent.

/**
     * If a notification with an ID is present.
     *
     * @param id
     *      Notification ID
     * @param command
     *      The callback context used when calling back into JavaScript.
     */
private void isPresent(int id, CallbackContext command) {
    boolean exist = getNotificationMgr().exist(id);
    PluginResult result = new PluginResult(PluginResult.Status.OK, exist);
    command.sendPluginResult(result);
}
Also used : PluginResult(org.apache.cordova.PluginResult)

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