List of usage examples for org.apache.cordova PluginResult setKeepCallback
public void setKeepCallback(boolean b)
From source file:fr.louisbl.cordova.gpslocation.CordovaGPSLocation.java
License:Apache License
/** * Location failed. Send error back to JavaScript. * * @param code/*from w w w.ja v a2s.c o m*/ * The error code * @param msg * The error message * @throws JSONException */ public void fail(int code, String msg, CallbackContext callbackContext, boolean keepCallback) { JSONObject obj = new JSONObject(); String backup = null; try { obj.put("code", code); obj.put("message", msg); } catch (JSONException e) { obj = null; backup = "{'code':" + code + ",'message':'" + msg.replaceAll("'", "\'") + "'}"; } PluginResult result; if (obj != null) { result = new PluginResult(PluginResult.Status.ERROR, obj); } else { result = new PluginResult(PluginResult.Status.ERROR, backup); } result.setKeepCallback(keepCallback); callbackContext.sendPluginResult(result); }
From source file:heron.cordova.plugin.baidutts.BaiduTts.java
@Override public void onSpeechStart(String s) { JSONObject jsonObject = new JSONObject(); try {/* w w w. j a va 2s. c o m*/ jsonObject.put("event", "onStart"); } catch (JSONException e) { e.printStackTrace(); } // send no result and keep callback PluginResult result = new PluginResult(PluginResult.Status.OK, jsonObject); result.setKeepCallback(true); currentCallbackContext.sendPluginResult(result); }
From source file:heron.cordova.plugin.baidutts.BaiduTts.java
@Override public void onSpeechFinish(String s) { JSONObject jsonObject = new JSONObject(); try {/*ww w. ja v a 2s . c om*/ jsonObject.put("event", "onStop"); } catch (JSONException e) { e.printStackTrace(); } // send no result and keep callback PluginResult result = new PluginResult(PluginResult.Status.OK, jsonObject); result.setKeepCallback(true); currentCallbackContext.sendPluginResult(result); }
From source file:heron.cordova.plugin.baidutts.BaiduTts.java
@Override public void onError(String s, SpeechError speechError) { JSONObject jsonObject = new JSONObject(); try {/* www. j a v a 2s.co m*/ jsonObject.put("event", "onStop"); } catch (JSONException e) { e.printStackTrace(); } // send no result and keep callback PluginResult result = new PluginResult(PluginResult.Status.ERROR, jsonObject); result.setKeepCallback(true); currentCallbackContext.sendPluginResult(result); }
From source file:ibp.plugin.nsd.NSDPlugin.java
License:Apache License
private void initNsd(CallbackContext callbackContext) { final CallbackContext cbc = callbackContext; initNsdCB = callbackContext;//w w w .j a v a2 s . c om try { if (null == mHandler) { mHandler = new Handler() { @Override public void handleMessage(Message msg) { String type = msg.getData().getString("type"); String message = msg.getData().getString("msg"); JSONObject data = new JSONObject(); try { data.put("type", new String(type)); data.put("data", new String(message)); } catch (JSONException e) { } PluginResult result = new PluginResult(PluginResult.Status.OK, data); result.setKeepCallback(true); cbc.sendPluginResult(result); } }; if (null == mNsdHelper) { mNsdHelper = new NSDHelper(cordova.getActivity(), mHandler); mNsdHelper.initializeNsd(); } PluginResult result = new PluginResult(PluginResult.Status.OK, "initNsd: success."); result.setKeepCallback(true); callbackContext.sendPluginResult(result); } else { PluginResult result = new PluginResult(PluginResult.Status.ERROR, "initNsd: Nsd Has been Initialized."); callbackContext.sendPluginResult(result); } } catch (Exception e) { PluginResult result = new PluginResult(PluginResult.Status.ERROR, "initNsd Exception: " + e); callbackContext.sendPluginResult(result); } }
From source file:ibp.plugin.socket.SocketPlugin.java
License:Apache License
private void initHandler(CallbackContext callbackContext) { final CallbackContext cbc = callbackContext; try {//from w w w . ja v a2 s . c o m if (null == mHandler) { mHandler = new Handler() { @Override public void handleMessage(Message msg) { PluginResult result = null; switch (msg.what) { case 0: result = new PluginResult(PluginResult.Status.OK, (JSONObject) msg.obj); result.setKeepCallback(true); break; case -1: result = new PluginResult(PluginResult.Status.NO_RESULT); mHandler = null; break; } cbc.sendPluginResult(result); } }; } PluginResult result = new PluginResult(PluginResult.Status.OK, "initHandler: success."); result.setKeepCallback(true); callbackContext.sendPluginResult(result); } catch (Exception e) { PluginResult result = new PluginResult(PluginResult.Status.ERROR, "initHandler Exception: " + e); callbackContext.sendPluginResult(result); } }
From source file:in.confest.fbaccountkit.FbAccountKit.java
License:Open Source License
private void login(final LoginType loginType, JSONArray args) { final Intent intent = new Intent(context(), AccountKitActivity.class); // TODO : extend the support to 'TOKEN' String responseType = "CODE"; PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT); r.setKeepCallback(true); callbackContext.sendPluginResult(r); AccountKitConfigurationBuilder configurationBuilder = new AccountKitConfigurationBuilder(loginType, AccountKitActivity.ResponseType.valueOf(responseType)); final AccountKitConfiguration configuration = configurationBuilder.build(); intent.putExtra(AccountKitActivity.ACCOUNT_KIT_ACTIVITY_CONFIGURATION, configuration); this.cordova.setActivityResultCallback(this); this.cordova.startActivityForResult(this, intent, LOGIN_REQUEST_CODE); }
From source file:info.snowhow.plugin.GPSTrack.java
License:Open Source License
@Override public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException { if (action.equals("record")) { String trackFile = args.getString(0); final JSONObject details = args.getJSONObject(1); final boolean adaptiveRecording = (boolean) args.getBoolean(2); final String trackName = args.getString(3); // set some default values here, see RecorderService for explanation final float precision = (float) details.optDouble("precision", 30); final long distanceChange = details.optLong("distance_change", 10); final long updateTime = details.optLong("update_time", 5000); final long updateTimeFast = details.optLong("update_time_fast", 1000); final long speedLimit = details.optLong("speed_limit", 5); if (trackFile.indexOf("file:///") > -1) { trackFile = trackFile.substring(7); }//from w w w .j av a2 s.c o m record(trackFile, precision, distanceChange, updateTime, updateTimeFast, speedLimit, adaptiveRecording, trackName); JSONObject obj = new JSONObject(); obj.put("test", 1); PluginResult res = new PluginResult(PluginResult.Status.OK, obj); res.setKeepCallback(true); callbackContext.sendPluginResult(res); Log.d(LOG_TAG, "done sending to webapp"); // cordova.getActivity().runOnUiThread(new Runnable() { // @Override // public void run() { // GPSTrack.this.record(trackFile); // // callbackContext.success(); // } // }); } else if (action.equals("listen")) { JSONObject obj = new JSONObject(); obj.put("test", 1); PluginResult res = new PluginResult(PluginResult.Status.OK, obj); res.setKeepCallback(true); callbackContext.sendPluginResult(res); Log.d(LOG_TAG, "done sending to webapp"); } else { return false; } return true; }
From source file:io.anyline.cordova.AnylinePlugin.java
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { mCallbackContext = callbackContext;//from ww w .j av a2s . c o m PluginResult result = null; Log.d(TAG, "Starting action: " + action); switch (action) { case "scanBarcode": case "BARCODE": scan(BarcodeActivity.class, REQUEST_BARCODE, args); break; case "scanMRZ": case "MRZ": scan(MrzActivity.class, REQUEST_MRZ, args); break; case "DEBIT_CARD": scan(DebitCardActivity.class, REQUEST_DEBIT_CARD, args); break; case "scanElectricMeter": case "ELECTRIC_METER": scanEnergy(args, EnergyScanView.ScanMode.ELECTRIC_METER); break; case "ELECTRIC_METER_6_1": scanEnergy(args, EnergyScanView.ScanMode.ELECTRIC_METER_6_1); break; case "ELECTRIC_METER_5_1": scanEnergy(args, EnergyScanView.ScanMode.ELECTRIC_METER_5_1); break; case "scanGasMeter": case "GAS_METER": scanEnergy(args, EnergyScanView.ScanMode.GAS_METER); break; case "WATER_METER_WHITE": scanEnergy(args, EnergyScanView.ScanMode.WATER_METER_WHITE); break; case "WATER_METER_BLACK": scanEnergy(args, EnergyScanView.ScanMode.WATER_METER_BLACK); break; case "DIGITAL_METER": scanEnergy(args, EnergyScanView.ScanMode.DIGITAL_METER); break; case "HEAT_METER_4": scanEnergy(args, EnergyScanView.ScanMode.HEAT_METER_4); break; case "HEAT_METER_5": scanEnergy(args, EnergyScanView.ScanMode.HEAT_METER_5); break; case "HEAT_METER_6": scanEnergy(args, EnergyScanView.ScanMode.HEAT_METER_6); break; case "SERIAL_NUMBER": scanEnergy(args, EnergyScanView.ScanMode.SERIAL_NUMBER); break; case "ANYLINE_OCR": scan(AnylineOcrActivity.class, REQUEST_ANYLINE_OCR, args); break; default: result = new PluginResult(Status.INVALID_ACTION); callbackContext .error(Resources.getString(cordova.getActivity(), "error_unkown_scan_mode") + " " + action); return false; } result = new PluginResult(Status.NO_RESULT); result.setKeepCallback(true); return true; }
From source file:io.anyline.cordova.AnylinePlugin.java
@Override public void onResult(Object result, boolean isFinalResult) { PluginResult pluginResult; if (result instanceof JSONObject) { pluginResult = new PluginResult(Status.OK, (JSONObject) result); } else if (result instanceof JSONArray) { pluginResult = new PluginResult(Status.OK, (JSONArray) result); } else {/*from w w w . j av a 2 s. c om*/ pluginResult = new PluginResult(Status.OK, result.toString()); } if (!isFinalResult) { pluginResult.setKeepCallback(true); } mCallbackContext.sendPluginResult(pluginResult); }