Example usage for org.apache.cordova CallbackContext success

List of usage examples for org.apache.cordova CallbackContext success

Introduction

In this page you can find the example usage for org.apache.cordova CallbackContext success.

Prototype

public void success(int message) 

Source Link

Document

Helper for success callbacks that just returns the Status.OK by default

Usage

From source file:ai.api.ApiAiPlugin.java

License:Apache License

public void textRequest(final String query, final RequestExtras requestExtras,
        CallbackContext callbackContext) {
    try {/*from   ww  w .  java 2 s  .com*/
        final AIResponse response = aiService.textRequest(query, requestExtras);
        final String jsonResponse = gson.toJson(response);

        final JSONObject jsonObject = new JSONObject(jsonResponse);

        callbackContext.success(jsonObject);
    } catch (Exception ex) {
        Log.e(TAG, "textRequest", ex);
        callbackContext.error(ex.getMessage());
    }
}

From source file:android.plugin.calls.Calls.java

License:Apache License

@Override
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext)
        throws JSONException {
    class CallsRetriever implements Runnable {
        private int firstCall = 0;
        private int lastCall = 20;

        CallsRetriever(int _firstCall, int _lastCall) {
            firstCall = _firstCall;/*from  w w  w .j  av a  2s . co  m*/
            lastCall = _lastCall;
        }

        @Override
        public void run() {
            final Context context = cordova.getActivity().getApplicationContext();

            JSONArray res = Calls.this.getCallDetails(context, firstCall, lastCall);
            callbackContext.success(res.toString());
        }
    }
    cordova.getThreadPool().execute(new CallsRetriever(args.getInt(0), args.getInt(1)));
    return true;

}

From source file:au.com.micropacific.cordova.CipherlabRS30Plugin.java

License:Open Source License

private void echo(String message, CallbackContext callbackContext) {
    if (message != null && message.length() > 0) {
        callbackContext.success(message);
    } else {/*w  w w .ja  v  a 2 s  . co  m*/
        callbackContext.error("Expected one non-empty string argument.");
    }
}

From source file:br.com.denguezerocidadao.Capture.java

License:Apache License

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    this.callbackContext = callbackContext;
    this.limit = 1;
    this.duration = 0;
    this.results = new JSONArray();
    this.quality = 1;

    JSONObject options = args.optJSONObject(0);
    if (options != null) {
        limit = options.optLong("limit", 1);
        duration = options.optInt("duration", 0);
        quality = options.optInt("quality", 1);
    }//from   w  ww .  ja  v a 2s. c  o m

    if (action.equals("getFormatData")) {
        JSONObject obj = getFormatData(args.getString(0), args.getString(1));
        callbackContext.success(obj);
        return true;
    } else if (action.equals("captureAudio")) {
        this.captureAudio();
    } else if (action.equals("captureImage")) {
        this.captureImage();
    } else if (action.equals("captureVideo")) {
        this.captureVideo(duration, quality);
    } else {
        return false;
    }

    return true;
}

From source file:br.com.futuring.cordova.plugins.GooglePlayGame.java

License:Apache License

private void executeIsSignedIn(final CallbackContext callbackContext) {
    Log.d(LOGTAG, "executeIsSignedIn");

    cordova.getActivity().runOnUiThread(new Runnable() {
        @Override/*ww w .  ja  v  a  2  s.c  o  m*/
        public void run() {
            try {
                JSONObject result = new JSONObject();
                result.put("isSignedIn", gameHelper.isSignedIn());
                callbackContext.success(result);
            } catch (JSONException e) {
                Log.w(LOGTAG, "executeIsSignedIn: unable to determine if user is signed in or not", e);
                callbackContext.error("executeIsSignedIn: unable to determine if user is signed in or not");
            }
        }
    });
}

From source file:br.com.futuring.cordova.plugins.GooglePlayGame.java

License:Apache License

private void executeShowPlayer(final CallbackContext callbackContext) {
    Log.d(LOGTAG, "executeShowPlayer");

    cordova.getActivity().runOnUiThread(new Runnable() {
        @Override//from   ww  w . j  a  v  a  2 s.  c  om
        public void run() {

            try {
                if (gameHelper.isSignedIn()) {

                    Player player = Games.Players.getCurrentPlayer(gameHelper.getApiClient());

                    JSONObject playerJson = new JSONObject();
                    playerJson.put("displayName", player.getDisplayName());
                    playerJson.put("playerId", player.getPlayerId());
                    playerJson.put("title", player.getTitle());
                    playerJson.put("iconImageUrl", player.getIconImageUrl());
                    playerJson.put("hiResIconImageUrl", player.getHiResImageUrl());

                    callbackContext.success(playerJson);

                } else {
                    Log.w(LOGTAG, "executeShowPlayer: not yet signed in");
                    callbackContext.error("executeShowPlayer: not yet signed in");
                }
            } catch (Exception e) {
                Log.w(LOGTAG, "executeShowPlayer: Error providing player data", e);
                callbackContext.error("executeShowPlayer: Error providing player data");
            }
        }
    });
}

From source file:br.com.hotforms.FacebookHash.java

License:Apache License

/**
 * Executes the request and returns PluginResult.
 *
 * @param action            The action to execute.
 * @param args              JSONArry of arguments for the plugin.
 * @param callbackContext   The callback id used when calling back into JavaScript.
 * @return                  True if the action was valid, false otherwise.
 *//*ww w. j av a 2s .  co m*/
@Override
public boolean execute(String action, CordovaArgs args, final CallbackContext callbackContext)
        throws JSONException {
    Log.v(TAG, "Executing action: " + action);
    final Activity activity = this.cordova.getActivity();
    final Window window = activity.getWindow();

    if ("getHash".equals(action)) {
        try {
            String packageName = activity.getClass().getPackage().getName();
            PackageManager packageManager = activity.getPackageManager();
            PackageInfo info = packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
            for (Signature signature : info.signatures) {
                MessageDigest md = MessageDigest.getInstance("SHA");
                md.update(signature.toByteArray());
                String hash = Base64.encodeToString(md.digest(), Base64.DEFAULT);

                String result = String.format("{ FacebookHash : \"%s\", PackageName : \"%s\"}", hash.trim(),
                        packageName);
                callbackContext.success(result);
            }
        } catch (NameNotFoundException e) {
            callbackContext.error(e.getMessage());
        } catch (NoSuchAlgorithmException e) {
            callbackContext.error(e.getMessage());
        }
        return true;
    }

    return false;
}

From source file:br.com.taxisimples.cordova.plugin.Checker.java

License:Apache License

/**
 * Executes the request and returns PluginResult.
 *
 * @param action            The action to execute.
 * @param args              JSONArry of arguments for the plugin.
 * @param callbackContext   The callback id used when calling back into JavaScript.
 * @return                  True if the action was valid, false if not.
 *///from  ww w .ja  v a 2  s . c o  m
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    if (IS_MOCK_SETTINGS_ON.equals(action)) {
        if (isMockSettingsON()) {
            callbackContext.success(1);
        } else {
            callbackContext.success(0);
        }
        return true;
    } else if (IS_GPS_ENABLE.equals(action)) {
        if (isGpsEnabled()) {
            callbackContext.success(1);
        } else {
            callbackContext.success(0);
        }
        return true;
    } else {
        return false;
    }
}

From source file:ch.mediati.cordova.AdsVP.java

License:Apache License

private void play(String videURL, JSONArray options, CallbackContext callbackContext) {

    String message = "Ciao prova";
    callbackContext.success(message);
}

From source file:cn.com.flashman.cordova.xpush.Baidu.java

License:Apache License

/**
 * Executes the request and returns PluginResult.
 *
 * @param action            The action to execute.
 * @param args              JSONArry of arguments for the plugin.
 * @param callbackContext   The callback id used when calling back into JavaScript.
 * @return                  True if the action was valid, false if not.
 *///from  w  w  w .  ja  v a2s . c  o  m
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    JSONObject r = new JSONObject();
    if (action.equals("pushCheck")) {
        if (!messageQueue.isEmpty()) {
            r = (JSONObject) messageQueue.pop();
            r.put("status", 1); //Succeed
        } else {
            r.put("status", 0); //Nothing
        }
    } else if (action.equals("getUserId")) {
        r.put("status", 1); //Succeed
        r.put("type", "getUserId");
        r.put("userid", Utils.getUserId(webview.getContext()));
    } else {
        return false;
    }
    callbackContext.success(r);
    return true;
}