Example usage for org.apache.cordova PluginResult PluginResult

List of usage examples for org.apache.cordova PluginResult PluginResult

Introduction

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

Prototype

public PluginResult(Status status) 

Source Link

Usage

From source file:com.firerunner.cordova.TTS.java

License:BSD License

/**
 * Once the utterance has completely been played call the speak's success callback
 *//*from w ww  . j av  a2 s  .c om*/
public void onUtteranceCompleted(String utteranceId) {
    PluginResult result = new PluginResult(PluginResult.Status.OK);
    result.setKeepCallback(false);
    this.callbackContext.sendPluginResult(result);
}

From source file:com.foxit.cordova.plugin.FoxitPdf.java

private boolean updateFormInfo(JSONObject formInfo, CallbackContext callbackContext) {
    if (ReaderActivity.pdfViewCtrl == null || ReaderActivity.pdfViewCtrl.getDoc() == null) {
        callbackContext.error("Please open document first.");
        return false;
    }//  w  w w .ja  v  a 2 s  . c o m

    PDFDoc pdfDoc = ReaderActivity.pdfViewCtrl.getDoc();
    try {
        if (!pdfDoc.hasForm()) {
            callbackContext.error("The current document does not have interactive form.");
            return false;
        }
        Form form = new Form(pdfDoc);

        boolean isModified = false;
        if (formInfo.has("alignment")) {
            int alignment = formInfo.getInt("alignment");
            form.setAlignment(alignment);
            isModified = true;
        }

        if (formInfo.has("needConstructAppearances")) {
            boolean needConstructAppearances = formInfo.getBoolean("needConstructAppearances");
            form.setConstructAppearances(needConstructAppearances);
            isModified = true;
        }

        if (formInfo.has("defaultAppearance")) {
            JSONObject daObj = formInfo.getJSONObject("defaultAppearance");
            DefaultAppearance da = form.getDefaultAppearance();
            if (daObj.has("flags")) {
                da.setFlags(daObj.getInt("flags"));
                isModified = true;
            }

            if (daObj.has("textSize")) {
                float textSize = BigDecimal.valueOf(daObj.getDouble("textSize")).floatValue();
                da.setText_size(textSize);
                isModified = true;
            }

            if (daObj.has("textColor")) {
                da.setText_color(daObj.getInt("textColor"));
                isModified = true;
            }

            form.setDefaultAppearance(da);
        }

        ((UIExtensionsManager) ReaderActivity.pdfViewCtrl.getUIExtensionsManager()).getDocumentManager()
                .setDocModified(isModified);
        callbackContext.success("Succeed to update form information.");
        return true;
    } catch (PDFException e) {
        callbackContext.error(e.getMessage() + ", Error code = " + e.getLastError());
    } catch (JSONException e) {
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
    }
    return false;
}

From source file:com.foxit.cordova.plugin.FoxitPdf.java

private boolean updateControl(int pageIndex, int controlIndex, JSONObject controlInfo,
        CallbackContext callbackContext) {
    if (ReaderActivity.pdfViewCtrl == null || ReaderActivity.pdfViewCtrl.getDoc() == null) {
        callbackContext.error("Please open document first.");
        return false;
    }/*from  w ww . j a va2  s.  co  m*/

    PDFDoc pdfDoc = ReaderActivity.pdfViewCtrl.getDoc();
    try {
        if (!pdfDoc.hasForm()) {
            callbackContext.error("The current document does not have interactive form.");
            return false;
        }
        Form form = new Form(pdfDoc);
        PDFPage page = pdfDoc.getPage(pageIndex);
        if (!page.isParsed()) {
            page.startParse(PDFPage.e_ParsePageNormal, null, false);
        }

        boolean isModified = false;
        Control control = form.getControl(page, controlIndex);
        if (controlInfo.has("exportValue")) {
            control.setExportValue(controlInfo.getString("exportValue"));
            isModified = true;
        }

        if (controlInfo.has("isChecked")) {
            control.setChecked(controlInfo.getBoolean("isChecked"));
            isModified = true;
        }

        if (controlInfo.has("isDefaultChecked")) {
            control.setDefaultChecked(controlInfo.getBoolean("isDefaultChecked"));
            isModified = true;
        }

        ((UIExtensionsManager) ReaderActivity.pdfViewCtrl.getUIExtensionsManager()).getDocumentManager()
                .setDocModified(isModified);
        callbackContext.success("Succeed to update the specified control information.");
        return true;
    } catch (PDFException e) {
        callbackContext.error(e.getMessage() + ", Error code = " + e.getLastError());
    } catch (JSONException e) {
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
    }
    return false;
}

From source file:com.foxit.cordova.plugin.FoxitPdf.java

private boolean updateField(int fieldIndex, JSONObject fieldInfo, CallbackContext callbackContext) {
    if (ReaderActivity.pdfViewCtrl == null || ReaderActivity.pdfViewCtrl.getDoc() == null) {
        callbackContext.error("Please open document first.");
        return false;
    }//from  w  ww. j  a  v a 2s. c o m

    PDFDoc pdfDoc = ReaderActivity.pdfViewCtrl.getDoc();
    try {
        if (!pdfDoc.hasForm()) {
            callbackContext.error("The current document does not have interactive form.");
            return false;
        }
        Form form = new Form(pdfDoc);
        Field field = form.getField(fieldIndex, null);

        boolean isModified = false;
        if (fieldInfo.has("fieldFlag")) {
            field.setFlags(fieldInfo.getInt("fieldFlag"));
            isModified = true;
        }

        if (fieldInfo.has("defValue")) {
            field.setDefaultValue(fieldInfo.getString("defValue"));
            isModified = true;
        }

        if (fieldInfo.has("value")) {
            field.setValue(fieldInfo.getString("value"));
            isModified = true;
        }

        if (fieldInfo.has("alignment")) {
            field.setAlignment(fieldInfo.getInt("alignment"));
            isModified = true;
        }

        if (fieldInfo.has("alternateName")) {
            field.setAlternateName(fieldInfo.getString("alternateName"));
            isModified = true;
        }

        if (fieldInfo.has("mappingName")) {
            field.setMappingName(fieldInfo.getString("mappingName"));
            isModified = true;
        }

        if (fieldInfo.has("maxLength")) {
            field.setMaxLength(fieldInfo.getInt("maxLength"));
            isModified = true;
        }

        if (fieldInfo.has("topVisibleIndex")) {
            field.setTopVisibleIndex(fieldInfo.getInt("topVisibleIndex"));
            isModified = true;
        }

        if (fieldInfo.has("defaultAppearance")) {
            JSONObject daObj = fieldInfo.getJSONObject("defaultAppearance");
            DefaultAppearance da = field.getDefaultAppearance();
            if (daObj.has("flags")) {
                da.setFlags(daObj.getInt("flags"));
                isModified = true;
            }

            if (daObj.has("textSize")) {
                float textSize = BigDecimal.valueOf(daObj.getDouble("textSize")).floatValue();
                da.setText_size(textSize);
                isModified = true;
            }

            if (daObj.has("textColor")) {
                da.setText_color(daObj.getInt("textColor"));
                isModified = true;
            }
            field.setDefaultAppearance(da);
        }

        if (fieldInfo.has("choiceOptions")) {
            int type = field.getType();
            if (type == Field.e_TypeListBox || type == Field.e_TypeComboBox) {
                JSONArray jsonArray = fieldInfo.getJSONArray("choiceOptions");
                if (jsonArray.length() > 0) {
                    ChoiceOptionArray optionArray = new ChoiceOptionArray();
                    for (int i = 0; i < jsonArray.length(); i++) {
                        ChoiceOption option = new ChoiceOption();
                        JSONObject jsonOption = jsonArray.getJSONObject(i);
                        if (jsonOption.has("optionValue")) {
                            option.setOption_value(jsonOption.getString("optionValue"));
                        }

                        if (jsonOption.has("optionLabel")) {
                            option.setOption_label(jsonOption.getString("optionLabel"));
                        }

                        if (jsonOption.has("selected")) {
                            option.setSelected(jsonOption.getBoolean("selected"));
                        }

                        if (jsonOption.has("defaultSelected")) {
                            option.setDefault_selected(jsonOption.getBoolean("defaultSelected"));
                        }

                        optionArray.add(option);
                    }
                    field.setOptions(optionArray);
                    isModified = true;
                }
            }
        }

        ((UIExtensionsManager) ReaderActivity.pdfViewCtrl.getUIExtensionsManager()).getDocumentManager()
                .setDocModified(isModified);
        callbackContext.success("Succeed to update the specified field information.");
        return true;
    } catch (PDFException e) {
        callbackContext.error(e.getMessage() + ", Error code = " + e.getLastError());
    } catch (JSONException e) {
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
    }
    return false;
}

From source file:com.gkcgautam.asset2sd.Asset2SD.java

License:Open Source License

/**
 * Executes the request and returns PluginResult.
 * //from   w w w.j a v a2 s .c  o m
 * @param action       The action to execute. (There is only a single action right now)
 * @param args          JSONArray of arguments for the plugin.
 * @param callbackId   The callback id used when calling back into JavaScript.
 * @return             A PluginResult object with a status.
 */
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
    Log.d(TAG, "Plugin Called");
    this.callbackContext = callbackContext;

    if (!SDCardExists()) {
        Log.e(TAG, "SD Card not mounted");
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR));
        return false;
    }

    try {

        if (args.length() != 1) {
            callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION));
            return false;
        }

        if (action.equals("copyFile")) {

            // Parse the arguments
            JSONObject obj = args.getJSONObject(0);
            String assetFile = obj.has("asset_file") ? obj.getString("asset_file") : null;
            String destinationFile = obj.has("destination_file") ? obj.getString("destination_file") : null;

            if (assetFile != null && destinationFile != null) {
                try {
                    String result_file_path = copyFile(assetFile, destinationFile);
                    Log.d(TAG, "File copied to -> " + result_file_path);
                    callbackContext
                            .sendPluginResult(new PluginResult(PluginResult.Status.OK, result_file_path));
                    return true;
                } catch (IOException e) {
                    Log.e(TAG, "Error occurred while copying file: " + e.getMessage());
                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR));
                    return false;
                }
            } else {
                Log.e(TAG, "copyFile : Parameter(s) missing");
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR));
                return false;
            }
        }

        if (action.equals("copyDir")) {

            // Parse the arguments
            JSONObject obj = args.getJSONObject(0);
            String asset_directory = obj.has("asset_directory") ? obj.getString("asset_directory") : null;
            String destination_directory = obj.has("destination_directory")
                    ? obj.getString("destination_directory")
                    : null;

            if (asset_directory != null && destination_directory != null) {
                try {
                    String result_dir_path = copyDir(asset_directory, destination_directory);
                    Log.d(TAG, "Directory copied to -> " + result_dir_path);
                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result_dir_path));
                    return true;
                } catch (IOException e) {
                    Log.e(TAG, "Error occurred while copying directory: " + e.getMessage());
                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR));
                    return false;
                }
            } else {
                Log.e(TAG, "copyDir : Parameter(s) missing");
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR));
                return false;
            }
        }

        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION));
        return false;
    } catch (JSONException e) {
        e.printStackTrace();
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
        return false;
    }
}

From source file:com.google.zxing.BarcodeScanner.java

License:BSD License

/**
* Executes the request and returns PluginResult.
*
* @param action        The action to execute.
* @param args          JSONArray of arguments for the plugin.
* @param callbackId    The callback id used when calling back into JavaScript.
* @return              A PluginResult object with a status and message.
*///from   ww w .j  a v a  2 s  .c  o  m
public PluginResult execute(String action, JSONArray args, String callbackId) {
    this.callback = callbackId;

    if (action.equals(SCAN)) {
        scan();
    } else {
        return new PluginResult(PluginResult.Status.INVALID_ACTION);
    }
    PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT);
    r.setKeepCallback(true);
    return r;
}

From source file:com.guaranteedshop.cordova.sms.SMSPlugin.java

public boolean execute(String action, JSONArray inputs, CallbackContext callbackContext) throws JSONException {
    PluginResult result = null;//from  ww w .  ja v a 2s.  c o m
    if (ACTION_SET_OPTIONS.equals(action)) {
        JSONObject options = inputs.optJSONObject(0);
        this.setOptions(options);
        result = new PluginResult(PluginResult.Status.OK);
    } else if (ACTION_START_WATCH.equals(action)) {
        result = this.startWatch(callbackContext);
    } else if (ACTION_STOP_WATCH.equals(action)) {
        result = this.stopWatch(callbackContext);
    } else if (ACTION_ENABLE_INTERCEPT.equals(action)) {
        boolean on_off = inputs.optBoolean(0);
        result = this.enableIntercept(on_off, callbackContext);
    } else if (ACTION_DELETE_SMS.equals(action)) {
        JSONObject msg = inputs.optJSONObject(0);
        result = this.deleteSMS(msg, callbackContext);
    } else if (ACTION_RESTORE_SMS.equals(action)) {
        JSONArray smsList = inputs.optJSONArray(0);
        result = this.restoreSMS(smsList, callbackContext);
    } else if (ACTION_LIST_SMS.equals(action)) {
        JSONObject filters = inputs.optJSONObject(0);
        result = this.listSMS(filters, callbackContext);
    } else if (ACTION_SEND_SMS.equals(action)) {
        JSONArray addressList = inputs.optJSONArray(0);
        String message = inputs.optString(1);
        result = this.sendSMS(addressList, message, callbackContext);
    } else {
        Log.d(LOGTAG, String.format("Invalid action passed: %s", action));
        result = new PluginResult(PluginResult.Status.INVALID_ACTION);
    }
    if (result != null) {
        callbackContext.sendPluginResult(result);
    }
    return true;
}

From source file:com.guinatal.refreshgallery.PluginRefreshGallery.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. java2 s.  c o m*/

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

    this.callbackContext = callbackContext;

    try {

        if (action.equals("refresh")) {

            String filePath = checkFilePath(args.getString(0));

            if (filePath.equals("")) {
                PluginResult r = new PluginResult(PluginResult.Status.ERROR);
                callbackContext.sendPluginResult(r);
                return true;
            }

            File file = new File(filePath);

            Intent scanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
            scanIntent.setData(Uri.fromFile(file));

            Context context = webView.getContext();
            context.sendBroadcast(scanIntent);
        }

        PluginResult r = new PluginResult(PluginResult.Status.OK);
        callbackContext.sendPluginResult(r);
        return true;

    } catch (JSONException e) {

        PluginResult r = new PluginResult(PluginResult.Status.JSON_EXCEPTION);
        callbackContext.sendPluginResult(r);
        return true;

    } catch (Exception e) {

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

From source file:com.ibm.mqtt.android.cordova.plugin.MqttPlugin.java

License:Open Source License

@Override
/**//from  w ww.j  a  v  a2  s . c  o m
 * This method takes the data passed through from javascript via "cordova.exec" and
 * makes appropriate method calls to the service.
 * Most calls will respond by broadcasting intents which our callbacklistener handles
 * 
 * This is a large method, but falls naturally into sections based on the action being
 * processed, so it doesn't seem necessary to split it into multiple methods.
 * 
 * @param action the action to be performed (see MqttServiceConstants)
 * @param args the parameters specified by the javascript code
 * @param callbackId 
 *       the callbackId which can be used to invoke to the success/failure callbacks
 *       provide to the cordova.execute call
 */
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
    traceDebug(TAG, "execute(" + action + ",{" + args + "}," + callbackContext.getCallbackId() + ")",
            callbackContext);
    try {
        if (action.equals(MqttServiceConstants.START_SERVICE_ACTION)) {
            if (mqttService != null) {
                traceDebug(TAG, "execute - service already started", callbackContext);
                return true;
            }
            serviceIntent = new Intent(context, MqttService.class);
            serviceIntent.putExtra(MqttServiceConstants.CALLBACK_ACTIVITY_TOKEN,
                    callbackContext.getCallbackId());
            ComponentName serviceComponentName = context.startService(serviceIntent);

            if (serviceComponentName == null) {
                traceError(TAG, "execute() - could not start " + MqttService.class, callbackContext);
                return false;
            }

            if (context.bindService(serviceIntent, serviceConnection, 0)) {
                // we return Status.NO_RESULT and setKeepCallback(true)
                // so that the callbackListener can use this callbackId
                // when it receives a connected event
                PluginResult result = new PluginResult(Status.NO_RESULT);
                result.setKeepCallback(true);

                callbackContext.sendPluginResult(result);
                return true;
            }
            return false;
        }

        if (action.equals(MqttServiceConstants.SET_TRACE_CALLBACK)) {
            // This is a trifle inelegant
            traceCallbackId = callbackContext.getCallbackId();
            if (mqttService != null) {
                mqttService.setTraceCallbackId(callbackContext.getCallbackId());
            }
            PluginResult result = new PluginResult(Status.NO_RESULT);
            result.setKeepCallback(true);

            callbackContext.sendPluginResult(result);
            return true;
        }

        if (action.equals(MqttServiceConstants.SET_TRACE_ENABLED)) {
            traceEnabled = true;
            if (mqttService != null) {
                mqttService.setTraceEnabled(traceEnabled);
            }
            PluginResult result = new PluginResult(Status.OK);

            callbackContext.sendPluginResult(result);
            return true;
        }

        if (action.equals(MqttServiceConstants.SET_TRACE_DISABLED)) {
            traceEnabled = false;
            if (mqttService != null) {
                mqttService.setTraceEnabled(traceEnabled);
            }
            PluginResult result = new PluginResult(Status.OK);

            callbackContext.sendPluginResult(result);
            return true;
        }

        if (mqttService == null) {
            return false;
        }

        if (action.equals(MqttServiceConstants.STOP_SERVICE_ACTION)) {
            Intent serviceIntent = new Intent(context, MqttService.class);
            context.stopService(serviceIntent);
            mqttService = null;
            return true;
        }

        if (action.equals(MqttServiceConstants.GET_CLIENT_ACTION)) {
            // This is a simple operation and we do it synchronously
            String clientHandle;
            try {
                String host = args.getString(0);
                int port = args.getInt(1);
                String clientId = args.getString(2);
                clientHandle = mqttService.getClient(host, port, clientId);

                // Set up somewhere to hold callbacks for this client
                callbackMap.put(clientHandle, new HashMap<String, String>());
            } catch (JSONException e) {
                traceException(TAG, "execute()", e, callbackContext);
                return false;
            }
            // We return a clientHandle to the javascript client,
            // which it can use to identify the client on subsequent calls
            return true;
        }

        // All remaining actions have a clientHandle as their first arg
        String clientHandle = args.getString(0);

        if (action.equals(MqttServiceConstants.CONNECT_ACTION)) {
            int timeout = args.getInt(1);
            boolean cleanSession = args.getBoolean(2);
            String userName = args.optString(3);
            String passWord = args.optString(4);
            int keepAliveInterval = args.getInt(5);
            JSONObject jsMsg = args.optJSONObject(6);
            MessagingMessage willMessage = (jsMsg == null) ? null : messageFromJSON(jsMsg, callbackContext);
            boolean useSSL = args.getBoolean(7);
            Properties sslProperties = null;
            JSONObject jsSslProperties = args.getJSONObject(8);
            if (jsSslProperties.length() != 0) {
                sslProperties = new Properties();
                Iterator<?> sslPropertyIterator = jsSslProperties.keys();
                while (sslPropertyIterator.hasNext()) {
                    String propertyName = (String) sslPropertyIterator.next();
                    String propertyValue = jsSslProperties.getString(propertyName);
                    sslProperties.put("com.ibm.ssl." + propertyName, propertyValue);
                }
            }
            String invocationContext = args.optString(9);
            mqttService.connect(clientHandle, timeout, cleanSession, userName, passWord, keepAliveInterval,
                    willMessage, useSSL, sslProperties, invocationContext, callbackContext.getCallbackId());
            PluginResult result = new PluginResult(Status.NO_RESULT);
            result.setKeepCallback(true);

            callbackContext.sendPluginResult(result);
            return true;
        }

        if (action.equals(MqttServiceConstants.DISCONNECT_ACTION)) {
            String invocationContext = args.optString(1);
            mqttService.disconnect(clientHandle, invocationContext, callbackContext.getCallbackId());
            PluginResult result = new PluginResult(Status.NO_RESULT);
            result.setKeepCallback(true);

            callbackContext.sendPluginResult(result);
            return true;
        }

        if (action.equals(MqttServiceConstants.SEND_ACTION)) {
            JSONObject jsMsg = args.getJSONObject(1);
            MessagingMessage msg = messageFromJSON(jsMsg, callbackContext);
            String invocationContext = args.optString(2);
            mqttService.send(clientHandle, msg, invocationContext, callbackContext.getCallbackId());
            // we return Status.NO_RESULT and setKeepCallback(true)
            // so that the callbackListener can use this callbackId
            // at an appropriate time - what time that is depends on
            // the qos value specified.
            PluginResult result = new PluginResult(Status.NO_RESULT);
            result.setKeepCallback(true);

            callbackContext.sendPluginResult(result);
            return true;
        }

        if (action.equals(MqttServiceConstants.SUBSCRIBE_ACTION)) {
            String topicFilter = args.getString(1);
            int qos = args.getInt(2);
            String invocationContext = args.optString(3);
            mqttService.subscribe(clientHandle, topicFilter, qos, invocationContext,
                    callbackContext.getCallbackId());
            // we return Status.NO_RESULT and setKeepCallback(true)
            // so that the callbackListener can use this callbackId
            // when it receives an event from the subscribe operation
            PluginResult result = new PluginResult(Status.NO_RESULT);
            result.setKeepCallback(true);

            callbackContext.sendPluginResult(result);
            return true;
        }

        if (action.equals(MqttServiceConstants.UNSUBSCRIBE_ACTION)) {
            String topicFilter = args.getString(1);
            String invocationContext = args.optString(2);
            mqttService.unsubscribe(clientHandle, topicFilter, invocationContext,
                    callbackContext.getCallbackId());
            // we return Status.NO_RESULT and setKeepCallback(true)
            // so that the callbackListener can use this callbackId
            // when it receives an event from the unsubscribe operation
            PluginResult result = new PluginResult(Status.NO_RESULT);
            result.setKeepCallback(true);

            callbackContext.sendPluginResult(result);
            return true;
        }

        if (action.equals(MqttServiceConstants.ACKNOWLEDGE_RECEIPT_ACTION)) {
            // This is a synchronous operation
            String id = args.getString(1);
            return mqttService.acknowledgeMessageArrival(clientHandle, id);
        }

        // The remaining actions are used to register callbacks for
        // "unsolicited" events
        if (action.equals(MqttServiceConstants.SET_ON_CONNECTIONLOST_CALLBACK)) {
            return setCallback(clientHandle, MqttServiceConstants.ON_CONNECTION_LOST_ACTION, callbackContext);
        }
        if (action.equals(MqttServiceConstants.SET_ON_MESSAGE_DELIVERED_CALLBACK)) {
            return setCallback(clientHandle, MqttServiceConstants.MESSAGE_DELIVERED_ACTION, callbackContext);
        }
        if (action.equals(MqttServiceConstants.SET_ON_MESSAGE_ARRIVED_CALLBACK)) {
            boolean setCallbackResult = setCallback(clientHandle, MqttServiceConstants.MESSAGE_ARRIVED_ACTION,
                    callbackContext);
            return setCallbackResult;
        }

    } catch (JSONException e) {
        return false;
    } catch (IllegalArgumentException e) {
        return false;
    }

    return false;
}

From source file:com.ibm.mqtt.android.cordova.plugin.MqttPlugin.java

License:Open Source License

private boolean setCallback(String clientHandle, String action, CallbackContext callbackContext) {
    Map<String /* action */, String /* callbackId */> clientCallbacks = callbackMap.get(clientHandle);
    if (clientCallbacks == null) {
        return false;
    }/*www  . j a  v a  2s  .  com*/
    clientCallbacks.put(action, callbackContext.getCallbackId());
    PluginResult result = new PluginResult(Status.NO_RESULT);
    result.setKeepCallback(true); // keep it around

    callbackContext.sendPluginResult(result);
    return true;
}