Example usage for org.apache.cordova.api CallbackContext sendPluginResult

List of usage examples for org.apache.cordova.api CallbackContext sendPluginResult

Introduction

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

Prototype

public void sendPluginResult(PluginResult pluginResult) 

Source Link

Usage

From source file:com.adobe.plugins.FastCanvas.java

License:Apache License

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    //Log.i("CANVAS", "FastCanvas execute: " + action);
    if (mMessageQueue == null) {
        Log.i("CANVAS", "FastCanvas messageQueue is NULL in execute.");
        return true;
    }/*from  w  w  w.  ja  v a  2s.  com*/

    try {

        if (action.equals("setBackgroundColor")) {
            FastCanvasMessage m = new FastCanvasMessage(FastCanvasMessage.Type.SET_BACKGROUND);
            m.drawCommands = args.getString(0);
            Log.i("CANVAS", "FastCanvas queueing set background color " + m.drawCommands);
            mMessageQueue.add(m);
            return true;

        } else if (action.equals("loadTexture")) {
            FastCanvasMessage m = new FastCanvasMessage(FastCanvasMessage.Type.LOAD);
            m.url = args.getString(0);
            m.textureID = args.getInt(1);
            assert callbackContext != null;
            m.callbackContext = callbackContext;
            Log.i("CANVAS", "FastCanvas queueing load texture " + m.textureID + ", " + m.url);
            mMessageQueue.add(m);
            return true;

        } else if (action.equals("unloadTexture")) {
            FastCanvasMessage m = new FastCanvasMessage(FastCanvasMessage.Type.UNLOAD);
            m.textureID = args.getInt(0);
            Log.i("CANVAS", "FastCanvas queueing unload texture " + m.textureID);
            mMessageQueue.add(m);
            return true;

        } else if (action.equals("render")) {
            FastCanvasMessage m = new FastCanvasMessage(FastCanvasMessage.Type.RENDER);
            m.drawCommands = args.getString(0);
            mMessageQueue.add(m);
            return true;

        } else if (action.equals("setOrtho")) {
            FastCanvasMessage m = new FastCanvasMessage(FastCanvasMessage.Type.SET_ORTHO);
            int width = args.getInt(0);
            int height = args.getInt(1);
            m.width = width;
            m.height = height;
            Log.i("CANVAS", "FastCanvas queueing setOrtho, width=" + m.width + ", height=" + m.height);
            mMessageQueue.add(m);
            return true;

        } else if (action.equals("capture")) {
            //set the root path to /mnt/sdcard/
            String fileLocation = Environment.getExternalStorageDirectory() + args.getString(4);
            String justPath = fileLocation.substring(0, fileLocation.lastIndexOf('/'));
            File directory = new File(justPath);
            if (!directory.isDirectory()) {
                //doesn't exist try to make it
                if (!directory.mkdirs()) {
                    //failed to make directory, callback with error
                    PluginResult result = new PluginResult(PluginResult.Status.ERROR,
                            "Could not create directory");
                    callbackContext.sendPluginResult(result);
                    return true;
                }
            }

            FastCanvasMessage m = new FastCanvasMessage(FastCanvasMessage.Type.CAPTURE);
            m.x = args.optInt(0, 0);
            m.y = args.optInt(1, 0);
            m.width = args.optInt(2, -1);
            m.height = args.optInt(3, -1);
            m.url = fileLocation;

            Log.i("CANVAS", "FastCanvas queueing capture");
            if (callbackContext != null)
                m.callbackContext = callbackContext;
            mMessageQueue.add(m);
            return true;

        } else if (action.equals("isAvailable")) {
            // user is checking to see if we exist
            // simply reply with a successful success callback
            // if we're not installed, cordova will call
            // the error callback for us
            PluginResult result = new PluginResult(PluginResult.Status.OK, true);
            callbackContext.sendPluginResult(result);
            // if for some other reason we are installed but 
            // cannot function, the result of OK above can be sent
            // but with a value of false which indicates unavailability
            // (may require not disabling the view if that's the case)
            return true;

        } else {
            Log.i("CANVAS", "FastCanvas unknown execute action " + action);
        }

    } catch (Exception e) {
        String argStr = "";
        try {
            argStr = args.join(",");
        } catch (Exception ignore) {
        }

        Log.e("CANVAS", "Unexpected error parsing execute parameters for action " + action + "(" + argStr + ")",
                e);
    }

    return false;
}

From source file:com.baroq.pico.google.PlayServices.java

@Override
public boolean execute(String action, JSONArray data, CallbackContext callbackContext) {

    try {/*from  ww  w . j  a  va 2 s. co m*/
        if (!ACTION_SETUP.equals(action) && !ACTION_SIGNIN.equals(action)
                && (null == mHelper || !mHelper.isConnected())) {
            callbackContext.error("Please setup and signin to use PlayServices plugin");
            return false;
        }
        if (ACTION_SETUP.equals(action)) {
            int l = data.length();
            if (0 == l) {
                callbackContext.error("Expecting at least 1 parameter for action: " + action);
                return false;
            }
            clientTypes = data.getInt(0);
            String[] extraScopes = new String[l - 1];
            for (int i = 1; i < l; i++) {
                extraScopes[i - 1] = data.getString(i);
            }
            setup(clientTypes, extraScopes, callbackContext);
            PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
            pluginResult.setKeepCallback(true);
            callbackContext.sendPluginResult(pluginResult);
        } else if (ACTION_SIGNIN.equals(action)) {
            mHelper.beginUserInitiatedSignIn();
            callbackContext.success();
        } else if (ACTION_SIGNOUT.equals(action)) {
            signout();
            callbackContext.success();
        } else if (ACTION_AS_MAX_KEYS.equals(action)) {
            PluginResult pluginResult = new PluginResult(PluginResult.Status.OK,
                    mHelper.getAppStateClient().getMaxNumKeys());
            pluginResult.setKeepCallback(false);
            callbackContext.sendPluginResult(pluginResult);
        } else if (ACTION_AS_MAX_SIZE.equals(action)) {
            PluginResult pluginResult = new PluginResult(PluginResult.Status.OK,
                    mHelper.getAppStateClient().getMaxStateSize());
            pluginResult.setKeepCallback(false);
            callbackContext.sendPluginResult(pluginResult);
        } else if (ACTION_AS_DEL.equals(action)) {
            int key = data.getInt(0);
            mHelper.getAppStateClient().deleteState(this, key);
            callbackContext.success();
        } else if (ACTION_AS_LIST.equals(action)) {
            mHelper.getAppStateClient().listStates(this);
            callbackContext.success();
        } else if (ACTION_AS_LOAD.equals(action)) {
            int key = data.getInt(0);
            mHelper.getAppStateClient().loadState(this, key);
            callbackContext.success();
        } else if (ACTION_AS_RESOLVE.equals(action)) {
            int key = data.getInt(0);
            String resolvedVersion = data.getString(1);
            String value = data.getString(2);
            mHelper.getAppStateClient().resolveState(this, key, resolvedVersion, value.getBytes());
            callbackContext.success();
        } else if (ACTION_AS_UPDATE.equals(action)) {
            int key = data.getInt(0);
            String value = data.getString(1);
            mHelper.getAppStateClient().updateState(key, value.getBytes());
            callbackContext.success();
        } else if (ACTION_AS_UPDATE_NOW.equals(action)) {
            int key = data.getInt(0);
            String value = data.getString(1);
            mHelper.getAppStateClient().updateStateImmediate(this, key, value.getBytes());
            callbackContext.success();
        } else if (ACTION_GAME_SHOW_ACHIEVEMENTS.equals(action)) {
            cordova.startActivityForResult((CordovaPlugin) this,
                    mHelper.getGamesClient().getAchievementsIntent(), RC_UNUSED);
            callbackContext.success();
        } else if (ACTION_GAME_SHOW_LEADERBOARDS.equals(action)) {
            cordova.startActivityForResult((CordovaPlugin) this,
                    mHelper.getGamesClient().getAllLeaderboardsIntent(), RC_UNUSED);
            callbackContext.success();
        } else if (ACTION_GAME_SHOW_LEADERBOARD.equals(action)) {
            String id = data.getString(0);
            cordova.startActivityForResult((CordovaPlugin) this,
                    mHelper.getGamesClient().getLeaderboardIntent(id), RC_UNUSED);
            callbackContext.success();
        } else if (ACTION_GAME_INCR_ACHIEVEMENT.equals(action)) {
            String id = data.getString(0);
            int numSteps = data.getInt(1);
            mHelper.getGamesClient().incrementAchievement(id, numSteps);
            callbackContext.success();
        } else if (ACTION_GAME_INCR_ACHIEVEMENT_NOW.equals(action)) {
            String id = data.getString(0);
            int numSteps = data.getInt(1);
            mHelper.getGamesClient().incrementAchievementImmediate(this, id, numSteps);
            callbackContext.success();
        } else if (ACTION_GAME_LOAD_ACHIEVEMENTS.equals(action)) {
            boolean forceReload = data.getBoolean(0);
            mHelper.getGamesClient().loadAchievements(this, forceReload);
            callbackContext.success();
        } else if (ACTION_GAME_LOAD_GAME.equals(action)) {
            mHelper.getGamesClient().loadGame(this);
            callbackContext.success();
        } else if (ACTION_GAME_LOAD_LEADERBOARD_METADATA.equals(action)) {
            if (1 == data.length()) {
                mHelper.getGamesClient().loadLeaderboardMetadata(this, data.getBoolean(0));
            } else {
                mHelper.getGamesClient().loadLeaderboardMetadata(this, data.getString(0), data.getBoolean(1));
            }
            callbackContext.success();
        } else if (ACTION_GAME_LOAD_MORE_SCORES.equals(action)) {
            if (null == scoreBuffer) {
                callbackContext.error("Get a leaderboard fist before calling: " + action);
                return false;
            }
            int maxResults = data.getInt(0);
            int pageDirection = data.getInt(0);
            mHelper.getGamesClient().loadMoreScores(this, scoreBuffer, maxResults, pageDirection);
            callbackContext.success();
        } else if (ACTION_GAME_LOAD_PLAYER.equals(action)) {
            String playerId = data.getString(0);
            mHelper.getGamesClient().loadPlayer(this, playerId);
            callbackContext.success();
        } else if (ACTION_GAME_LOAD_PLAYER_CENTERED_SCORES.equals(action)) {
            String leaderboardId = data.getString(0);
            int span = data.getInt(1);
            int leaderboardCollection = data.getInt(2);
            int maxResults = data.getInt(3);
            if (data.isNull(4)) {
                mHelper.getGamesClient().loadPlayerCenteredScores(this, leaderboardId, span,
                        leaderboardCollection, maxResults);
            } else {
                boolean forceReload = data.getBoolean(4);
                mHelper.getGamesClient().loadPlayerCenteredScores(this, leaderboardId, span,
                        leaderboardCollection, maxResults, forceReload);
            }
            callbackContext.success();
        } else if (ACTION_GAME_LOAD_TOP_SCORES.equals(action)) {
            String leaderboardId = data.getString(0);
            int span = data.getInt(1);
            int leaderboardCollection = data.getInt(2);
            int maxResults = data.getInt(3);
            if (data.isNull(4)) {
                mHelper.getGamesClient().loadTopScores(this, leaderboardId, span, leaderboardCollection,
                        maxResults);
            } else {
                boolean forceReload = data.getBoolean(4);
                mHelper.getGamesClient().loadTopScores(this, leaderboardId, span, leaderboardCollection,
                        maxResults, forceReload);
            }
            callbackContext.success();
        } else if (ACTION_GAME_REVEAL_ACHIEVEMENT.equals(action)) {
            String id = data.getString(0);
            mHelper.getGamesClient().revealAchievement(id);
            callbackContext.success();
        } else if (ACTION_GAME_REVEAL_ACHIEVEMENT_NOW.equals(action)) {
            String id = data.getString(0);
            mHelper.getGamesClient().revealAchievementImmediate(this, id);
            callbackContext.success();
        } else if (ACTION_GAME_SUBMIT_SCORE.equals(action)) {
            String leaderboardId = data.getString(0);
            int score = data.getInt(1);
            mHelper.getGamesClient().submitScore(leaderboardId, score);
            callbackContext.success();
        } else if (ACTION_GAME_SUBMIT_SCORE_NOW.equals(action)) {
            String leaderboardId = data.getString(0);
            int score = data.getInt(1);
            mHelper.getGamesClient().submitScoreImmediate(this, leaderboardId, score);
            callbackContext.success();
        } else if (ACTION_GAME_UNLOCK_ACHIEVEMENT.equals(action)) {
            String id = data.getString(0);
            mHelper.getGamesClient().unlockAchievement(id);
            callbackContext.success();
        } else if (ACTION_GAME_UNLOCK_ACHIEVEMENT_NOW.equals(action)) {
            String id = data.getString(0);
            mHelper.getGamesClient().unlockAchievementImmediate(this, id);
            callbackContext.success();
        } else {
            callbackContext.error("Unknown action: " + action);
            return false;
        }
    } catch (JSONException ex) {
        callbackContext.error(ex.getMessage());
        return false;
    }

    return true;
}

From source file:com.cbtec.eliademy.FacebookConnect.java

License:Open Source License

@Override
public boolean execute(String action, JSONArray args, final CallbackContext callbackId) {
    PluginResult pluginResult = new PluginResult(PluginResult.Status.INVALID_ACTION,
            "Unsupported operation: " + action);

    try {/*  w  w w.  j  a  v  a2s  .  co  m*/
        if (action.equals("initWithAppId"))
            pluginResult = this.initWithAppId(args, callbackId);
        else if (action.equals("login"))
            pluginResult = this.login(args, callbackId);
        else if (action.equals("requestWithGraphPath"))
            pluginResult = this.requestWithGraphPath(args, callbackId);
        else if (action.equals("dialog"))
            pluginResult = this.dialog(args, callbackId);
        else if (action.equals("logout"))
            pluginResult = this.logout(args, callbackId);
    } catch (MalformedURLException e) {
        e.printStackTrace();
        pluginResult = new PluginResult(PluginResult.Status.MALFORMED_URL_EXCEPTION);
    } catch (IOException e) {
        e.printStackTrace();
        pluginResult = new PluginResult(PluginResult.Status.IO_EXCEPTION);
    } catch (JSONException e) {
        e.printStackTrace();
        pluginResult = new PluginResult(PluginResult.Status.JSON_EXCEPTION);
    }

    callbackId.sendPluginResult(pluginResult);
    return true;
}

From source file:com.example.testplayer.NetworkManager.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.
 *//*from  w  w  w . ja  v a2 s . c  o m*/
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
    if (action.equals("getConnectionInfo")) {
        this.connectionCallbackContext = callbackContext;
        NetworkInfo info = sockMan.getActiveNetworkInfo();
        String connectionType = "";
        try {
            connectionType = this.getConnectionInfo(info).get("type").toString();
        } catch (JSONException e) {
        }

        PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, connectionType);
        pluginResult.setKeepCallback(true);
        callbackContext.sendPluginResult(pluginResult);
        return true;
    }
    return false;
}

From source file:com.foregroundgalleryplugin.ForegroundGalleryLauncher.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                 A PluginResult object with a status and message.
 *//*from  w  w  w  .  j  a v a2 s  . c  o  m*/
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {

    this.callbackContext = callbackContext;

    this.targetHeight = 0;
    this.targetWidth = 0;
    this.mQuality = 80;

    JSONObject options = args.optJSONObject(0);
    if (options != null) {
        this.targetHeight = options.getInt("targetHeight");
        this.targetWidth = options.getInt("targetWidth");
        this.mQuality = options.getInt("quality");
    }

    this.getImage();

    PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT);
    r.setKeepCallback(true);
    callbackContext.sendPluginResult(r);
    return true;
}

From source file:com.getkickbak.plugin.NotificationPlugin.java

License:Apache License

/**
 * Builds and shows a native Android alert with given Strings
 * /*from   ww  w  .  j a v a2s . c  o m*/
 * @param message
 *           The message the alert should display
 * @param title
 *           The title of the alert
 * @param buttonLabel
 *           The label of the button
 * @param callbackContext
 *           The callback context
 */
public synchronized void alert(final String message, final String title, final String buttonLabel,
        final CallbackContext callbackContext) {

    final CordovaInterface cordova = this.cordova;

    Runnable runnable = new Runnable() {
        public void run() {

            AlertDialog.Builder dlg = new AlertDialog.Builder(cordova.getActivity());
            dlg.setMessage(message);
            dlg.setTitle(title);
            dlg.setCancelable(true);
            dlg.setPositiveButton(buttonLabel, new AlertDialog.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0));
                }
            });
            dlg.setOnCancelListener(new AlertDialog.OnCancelListener() {
                public void onCancel(DialogInterface dialog) {
                    dialog.dismiss();
                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0));
                }
            });

            dlg.create();
            dlg.show();
        };
    };
    this.cordova.getActivity().runOnUiThread(runnable);
}

From source file:com.getkickbak.plugin.NotificationPlugin.java

License:Apache License

/**
 * Builds and shows a native Android confirm dialog with given title, message, buttons.
 * This dialog only shows up to 3 buttons. Any labels after that will be ignored.
 * The index of the button pressed will be returned to the JavaScript callback identified by callbackId.
 * //from   w ww .ja  v  a  2s. com
 * @param message
 *           The message the dialog should display
 * @param title
 *           The title of the dialog
 * @param buttonLabels
 *           A comma separated list of button labels (Up to 3 buttons)
 * @param callbackContext
 *           The callback context.
 */
public synchronized void confirm(final String message, final String title, String buttonLabels,
        final CallbackContext callbackContext) {

    final NotificationPlugin notification = this;
    final CordovaInterface cordova = this.cordova;
    final String[] fButtons = (buttonLabels != null) ? buttonLabels.split(",") : new String[0];

    Runnable runnable = new Runnable() {
        public void run() {
            AlertDialog.Builder dlg = new AlertDialog.Builder(cordova.getActivity());
            dlg.setMessage(message);
            dlg.setTitle(title);
            dlg.setCancelable((fButtons.length > 0) ? true : false);

            // First button
            if (fButtons.length > 0) {
                dlg.setNegativeButton(fButtons[0], new AlertDialog.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        notification.dismiss(-1, dialog);
                        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 1));
                    }
                });
                dlg.setOnCancelListener(new AlertDialog.OnCancelListener() {
                    public void onCancel(DialogInterface dialog) {
                        notification.dismiss(-1, dialog);
                        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0));
                    }
                });
            }

            // Second button
            if (fButtons.length > 1) {
                dlg.setNeutralButton(fButtons[1], new AlertDialog.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        notification.dismiss(-1, dialog);
                        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 2));
                    }
                });
            }

            // Third button
            if (fButtons.length > 2) {
                dlg.setPositiveButton(fButtons[2], new AlertDialog.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        notification.dismiss(-1, dialog);
                        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 3));
                    }
                });
            }
            /*
             * dlg.setOnDismissListener(new AlertDialog.OnDismissListener()
             * {
             * public void onDismiss(DialogInterface dialog)
             * {
             * }
             * });
             */

            dlg.create();
            Integer key = Integer.valueOf(((int) (Math.random() * 10000000)) + 10000);
            AlertDialog value = dlg.show();

            notification.dialogsIA.put(key, value);
            notification.dialogsAI.put(value, key);
            if (fButtons.length == 0) {
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, key.intValue()));
            }
        };
    };
    this.cordova.getActivity().runOnUiThread(runnable);
}

From source file:com.giedrius.plugin.LFOpenPlugin.java

@Override
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext)
        throws JSONException {

    if (ACTION_GET_WORKOUT_OBJ.equals(action)) {

        cordova.getThreadPool().execute(new Runnable() {
            public void run() {

                //Intent intent = new Intent(Intent.ACTION_EDIT).setType("vnd.android.cursor.item/event");
                //this.cordova.getActivity().startActivity(intent);
                //showCalendar(action, args, callbackContext);

                //Intent intent = new Intent(cordova.getActivity(), WorkoutActivity.class);
                //cordova.getActivity().startActivity(intent);
                //callbackContext.success();
                LFOpenEquipmentObserver lfopen = new LFOpenEquipmentObserver();
                JSONObject workoutJsonObj = new JSONObject();
                WorkoutStream workoutObj = lfopen.getWorkoutObj();

                // put workout details into JSON object
                try {
                    workoutJsonObj.put("accumulatedCalories",
                            getRoundedValue(workoutObj.getAccumulatedCalories()));
                    workoutJsonObj.put("accumulatedDistance",
                            getRoundedValue(workoutObj.getAccumulatedDistance()));
                    workoutJsonObj.put("accumulatedDistanceClimbed",
                            getRoundedValue(workoutObj.getAccumulatedDistanceClimbed()));
                    workoutJsonObj.put("currentHeartRate", getRoundedValue(workoutObj.getCurrentHeartRate()));
                    workoutJsonObj.put("currentIncline", getRoundedValue(workoutObj.getCurrentIncline()));
                    workoutJsonObj.put("currentLevel", getRoundedValue(workoutObj.getCurrentLevel()));
                    workoutJsonObj.put("currentResistance", getRoundedValue(workoutObj.getCurrentResistance()));
                    workoutJsonObj.put("currentSpeed", getRoundedValue(workoutObj.getCurrentSpeed()));
                    workoutJsonObj.put("currentSpeedRPM", getRoundedValue(workoutObj.getCurrentSpeedRPM()));
                    workoutJsonObj.put("targetCalories", getRoundedValue(workoutObj.getTargetCalories()));
                    workoutJsonObj.put("targetDistance", getRoundedValue(workoutObj.getTargetDistance()));
                    workoutJsonObj.put("targetDistanceClibmed",
                            getRoundedValue(workoutObj.getTargetDistanceClibmed()));
                    workoutJsonObj.put("targetHeartRate", getRoundedValue(workoutObj.getTargetHeartRate()));
                    workoutJsonObj.put("targetIncline", getRoundedValue(workoutObj.getTargetIncline()));
                    workoutJsonObj.put("targetSpeed", getRoundedValue(workoutObj.getTargetSpeed()));
                    workoutJsonObj.put("targetWorkoutSeconds",
                            getRoundedValue(workoutObj.getTargetWorkoutSeconds()));
                    workoutJsonObj.put("workoutElapseSeconds",
                            getRoundedValue(workoutObj.getWorkoutElapseSeconds()));
                    workoutJsonObj.put("workoutState", workoutObj.getWorkoutState());
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }//from  w  ww. j  av a2s .c  o m

                callbackContext.sendPluginResult(new PluginResult(Status.OK, workoutJsonObj));
                //callbackContext.success();
            }
        });
        return true;
    }
    callbackContext.error("Invalid action");
    return false;
}

From source file:com.google.cordova.ChromeBootstrap.java

License:Open Source License

@Override
public boolean execute(String action, CordovaArgs args, final CallbackContext callbackContext)
        throws JSONException {
    if ("doesNeedLaunch".equals(action)) {
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, true));
        return true;
    }//from   w  w w  .  j  a  v  a 2  s  . co  m
    return false;
}

From source file:com.google.cordova.ChromeSocket.java

License:Open Source License

private void create(CordovaArgs args, final CallbackContext callbackContext) throws JSONException {
    String socketType = args.getString(0);
    if (socketType.equals("tcp") || socketType.equals("udp")) {
        SocketData sd = new SocketData(socketType.equals("tcp") ? SocketData.Type.TCP : SocketData.Type.UDP);
        int id = addSocket(sd);
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, id));
    } else {/*from  ww w . java2 s  . com*/
        Log.e(LOG_TAG, "Unknown socket type: " + socketType);
    }
}