Java Code Examples for org.apache.cordova.CallbackContext#sendPluginResult()
The following examples show how to use
org.apache.cordova.CallbackContext#sendPluginResult() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NetworkManager.java From jpHolo with MIT License | 6 votes |
/** * 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. */ 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; }
Example 2
Source File: NetworkManager.java From showCaseCordova with Apache License 2.0 | 6 votes |
/** * 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. */ 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; }
Example 3
Source File: FileTransfer.java From reader with MIT License | 6 votes |
@Override public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException { if (action.equals("upload") || action.equals("download")) { String source = args.getString(0); String target = args.getString(1); if (action.equals("upload")) { try { source = URLDecoder.decode(source, "UTF-8"); upload(source, target, args, callbackContext); } catch (UnsupportedEncodingException e) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.MALFORMED_URL_EXCEPTION, "UTF-8 error.")); } } else { download(source, target, args, callbackContext); } return true; } else if (action.equals("abort")) { String objectId = args.getString(0); abort(objectId); callbackContext.success(); return true; } return false; }
Example 4
Source File: FileTransfer.java From reacteu-app with MIT License | 6 votes |
@Override public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException { if (action.equals("upload") || action.equals("download")) { String source = args.getString(0); String target = args.getString(1); if (action.equals("upload")) { try { source = URLDecoder.decode(source, "UTF-8"); upload(source, target, args, callbackContext); } catch (UnsupportedEncodingException e) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.MALFORMED_URL_EXCEPTION, "UTF-8 error.")); } } else { download(source, target, args, callbackContext); } return true; } else if (action.equals("abort")) { String objectId = args.getString(0); abort(objectId); callbackContext.success(); return true; } return false; }
Example 5
Source File: AccelListener.java From showCaseCordova with Apache License 2.0 | 6 votes |
/** * Executes the request. * * @param action The action to execute. * @param args The exec() arguments. * @param callbackId The callback id used when calling back into JavaScript. * @return Whether the action was valid. */ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { if (action.equals("start")) { this.callbackContext = callbackContext; if (this.status != AccelListener.RUNNING) { // If not running, then this is an async call, so don't worry about waiting // We drop the callback onto our stack, call start, and let start and the sensor callback fire off the callback down the road this.start(); } } else if (action.equals("stop")) { if (this.status == AccelListener.RUNNING) { this.stop(); } } else { // Unsupported action return false; } PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT, ""); result.setKeepCallback(true); callbackContext.sendPluginResult(result); return true; }
Example 6
Source File: DisconnectionTask.java From WebSocket-for-Android with Apache License 2.0 | 6 votes |
@Override public void execute(String rawArgs, CallbackContext ctx) { try { JSONArray args = new JSONArray(rawArgs); int id = Integer.parseInt(args.getString(0), 16); int code = args.getInt(1); String reason = args.getString(2); Connection conn = _map.get(id); if (conn != null) { if (code > 0) { conn.close(code, reason); } else { conn.close(); } } } catch (Exception e) { if (!ctx.isFinished()) { PluginResult result = new PluginResult(Status.ERROR); result.setKeepCallback(true); ctx.sendPluginResult(result); } } }
Example 7
Source File: IMEIPlugin.java From cordova-plugin-imei with MIT License | 5 votes |
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { PluginResult.Status status = PluginResult.Status.OK; String result = ""; if (action.equals("get")) { TelephonyManager telephonyManager = (TelephonyManager)this.cordova.getActivity().getSystemService(Context.TELEPHONY_SERVICE); result = telephonyManager.getDeviceId(); } else { status = PluginResult.Status.INVALID_ACTION; } callbackContext.sendPluginResult(new PluginResult(status, result)); return true; }
Example 8
Source File: FileUtils.java From reacteu-app with MIT License | 5 votes |
/** * Requests a filesystem in which to store application data. * * @param type of file system requested * @param requiredSize required free space in the file system in bytes * @param callbackContext context for returning the result or error * @throws JSONException */ private void requestFileSystem(int type, long requiredSize, final CallbackContext callbackContext) throws JSONException { Filesystem rootFs = null; try { rootFs = this.filesystems.get(type); } catch (ArrayIndexOutOfBoundsException e) { // Pass null through } if (rootFs == null) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, FileUtils.NOT_FOUND_ERR)); } else { // If a nonzero required size was specified, check that the retrieved filesystem has enough free space. long availableSize = 0; if (requiredSize > 0) { availableSize = rootFs.getFreeSpaceInBytes(); } if (availableSize < requiredSize) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, FileUtils.QUOTA_EXCEEDED_ERR)); } else { JSONObject fs = new JSONObject(); fs.put("name", rootFs.name); fs.put("root", rootFs.getRootEntry()); callbackContext.success(fs); } } }
Example 9
Source File: FileUtils.java From keemob with MIT License | 5 votes |
/** * Requests a filesystem in which to store application data. * * @param type of file system requested * @param requiredSize required free space in the file system in bytes * @param callbackContext context for returning the result or error * @throws JSONException */ private void requestFileSystem(int type, long requiredSize, final CallbackContext callbackContext) throws JSONException { Filesystem rootFs = null; try { rootFs = this.filesystems.get(type); } catch (ArrayIndexOutOfBoundsException e) { // Pass null through } if (rootFs == null) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, FileUtils.NOT_FOUND_ERR)); } else { // If a nonzero required size was specified, check that the retrieved filesystem has enough free space. long availableSize = 0; if (requiredSize > 0) { availableSize = rootFs.getFreeSpaceInBytes(); } if (availableSize < requiredSize) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, FileUtils.QUOTA_EXCEEDED_ERR)); } else { JSONObject fs = new JSONObject(); fs.put("name", rootFs.name); fs.put("root", rootFs.getRootEntry()); callbackContext.success(fs); } } }
Example 10
Source File: BackgroundServicePlugin.java From cbsp with MIT License | 5 votes |
private void sendUpdateToListener(ExecuteResult logicResult, Object[] listenerExtras) { try { if (listenerExtras != null && listenerExtras.length > 0) { Log.d(TAG, "Sending update"); CallbackContext callback = (CallbackContext)listenerExtras[0]; callback.sendPluginResult(transformResult(logicResult)); Log.d(TAG, "Sent update"); } } catch (Exception ex) { Log.d(TAG, "Sending update failed", ex); } }
Example 11
Source File: TwilioVoicePlugin.java From cordova-plugin-twiliovoicesdk with MIT License | 5 votes |
private void callStatus(CallbackContext callbackContext) { if (mCall == null) { callbackContext.sendPluginResult(new PluginResult( PluginResult.Status.ERROR)); return; } String state = getCallState(mCall.getState()); if (state == null) { state = ""; } PluginResult result = new PluginResult(PluginResult.Status.OK, state); callbackContext.sendPluginResult(result); }
Example 12
Source File: HotCodePushPlugin.java From cordova-hot-code-push with MIT License | 5 votes |
/** * Get information about app and web versions. * * @param callback callback where to send the result */ private void jsGetVersionInfo(final CallbackContext callback) { final Context context = cordova.getActivity(); final Map<String, Object> data = new HashMap<String, Object>(); data.put("currentWebVersion", pluginInternalPrefs.getCurrentReleaseVersionName()); data.put("readyToInstallWebVersion", pluginInternalPrefs.getReadyForInstallationReleaseVersionName()); data.put("previousWebVersion", pluginInternalPrefs.getPreviousReleaseVersionName()); data.put("appVersion", VersionHelper.applicationVersionName(context)); data.put("buildVersion", VersionHelper.applicationVersionCode(context)); final PluginResult pluginResult = PluginResultHelper.createPluginResult(null, data, null); callback.sendPluginResult(pluginResult); }
Example 13
Source File: ShortcutsPlugin.java From cordova-plugin-shortcuts-android with MIT License | 4 votes |
private void getIntent(CallbackContext callbackContext) throws JSONException { Intent intent = this.cordova.getActivity().getIntent(); PluginResult result = new PluginResult(PluginResult.Status.OK, buildIntent(intent)); callbackContext.sendPluginResult(result); }
Example 14
Source File: BluetoothPlugin.java From phonegap-bluetooth-plugin with MIT License | 4 votes |
/** * Start a device discovery. * * @param args Arguments given. * @param callbackCtx Where to send results. */ private void startDiscovery(JSONArray args, CallbackContext callbackCtx) { // TODO Someday add an option to fetch UUIDs at the same time try { if(_bluetooth.isConnecting()) { this.error(callbackCtx, "A Connection attempt is in progress.", BluetoothError.ERR_CONNECTING_IN_PROGRESS); } else { if(_bluetooth.isDiscovering()) { _wasDiscoveryCanceled = true; _bluetooth.stopDiscovery(); if(_discoveryCallback != null) { this.error(_discoveryCallback, "Discovery was stopped because a new discovery was started.", BluetoothError.ERR_DISCOVERY_RESTARTED ); _discoveryCallback = null; } } _bluetooth.startDiscovery(); PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT); result.setKeepCallback(true); callbackCtx.sendPluginResult(result); _discoveryCallback = callbackCtx; } } catch(Exception e) { this.error(callbackCtx, e.getMessage(), BluetoothError.ERR_UNKNOWN); } }
Example 15
Source File: App.java From phonegap-plugin-loading-spinner with Apache License 2.0 | 4 votes |
/** * Executes the request and returns PluginResult. * * @param action The action to execute. * @param args JSONArry of arguments for the plugin. * @param callbackContext The callback context from which we were invoked. * @return A PluginResult object with a status and message. */ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { PluginResult.Status status = PluginResult.Status.OK; String result = ""; try { if (action.equals("clearCache")) { this.clearCache(); } else if (action.equals("show")) { // This gets called from JavaScript onCordovaReady to show the webview. // I recommend we change the name of the Message as spinner/stop is not // indicative of what this actually does (shows the webview). cordova.getActivity().runOnUiThread(new Runnable() { public void run() { webView.postMessage("spinner", "stop"); } }); } else if (action.equals("loadUrl")) { this.loadUrl(args.getString(0), args.optJSONObject(1)); } else if (action.equals("cancelLoadUrl")) { //this.cancelLoadUrl(); } else if (action.equals("clearHistory")) { this.clearHistory(); } else if (action.equals("backHistory")) { this.backHistory(); } else if (action.equals("overrideButton")) { this.overrideButton(args.getString(0), args.getBoolean(1)); } else if (action.equals("overrideBackbutton")) { this.overrideBackbutton(args.getBoolean(0)); } else if (action.equals("exitApp")) { this.exitApp(); } callbackContext.sendPluginResult(new PluginResult(status, result)); return true; } catch (JSONException e) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION)); return false; } }
Example 16
Source File: InAppServicePlugin.java From atomic-plugins-inapps with Mozilla Public License 2.0 | 4 votes |
public void canPurchase(CordovaArgs args, CallbackContext ctx) { ctx.sendPluginResult(new PluginResult(Status.OK, service.canPurchase())); }
Example 17
Source File: Globalization.java From jpHolo with MIT License | 4 votes |
@Override public boolean execute(String action, JSONArray data, CallbackContext callbackContext) { JSONObject obj = new JSONObject(); try{ if (action.equals(GETLOCALENAME)){ obj = getLocaleName(); }else if (action.equals(GETPREFERREDLANGUAGE)){ obj = getPreferredLanguage(); } else if (action.equalsIgnoreCase(DATETOSTRING)) { obj = getDateToString(data); }else if(action.equalsIgnoreCase(STRINGTODATE)){ obj = getStringtoDate(data); }else if(action.equalsIgnoreCase(GETDATEPATTERN)){ obj = getDatePattern(data); }else if(action.equalsIgnoreCase(GETDATENAMES)){ if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.GINGERBREAD) { throw new GlobalizationError(GlobalizationError.UNKNOWN_ERROR); } else { obj = getDateNames(data); } }else if(action.equalsIgnoreCase(ISDAYLIGHTSAVINGSTIME)){ obj = getIsDayLightSavingsTime(data); }else if(action.equalsIgnoreCase(GETFIRSTDAYOFWEEK)){ obj = getFirstDayOfWeek(data); }else if(action.equalsIgnoreCase(NUMBERTOSTRING)){ obj = getNumberToString(data); }else if(action.equalsIgnoreCase(STRINGTONUMBER)){ obj = getStringToNumber(data); }else if(action.equalsIgnoreCase(GETNUMBERPATTERN)){ obj = getNumberPattern(data); }else if(action.equalsIgnoreCase(GETCURRENCYPATTERN)){ obj = getCurrencyPattern(data); }else { return false; } callbackContext.success(obj); }catch (GlobalizationError ge){ callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, ge.toJson())); }catch (Exception e){ callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION)); } return true; }
Example 18
Source File: InAppServicePlugin.java From atomic-plugins-inapps with Mozilla Public License 2.0 | 4 votes |
public void getProducts(CordovaArgs args, CallbackContext ctx) { ctx.sendPluginResult(new PluginResult(Status.OK, productsToJSON(service.getProducts()))); }
Example 19
Source File: InAppServicePlugin.java From atomic-plugins-inapps with Mozilla Public License 2.0 | 4 votes |
public void isPurchased(CordovaArgs args, CallbackContext ctx) { String productId = args.optString(0); boolean purchased = productId != null ? service.isPurchased(productId) : false; ctx.sendPluginResult(new PluginResult(Status.OK, purchased)); }
Example 20
Source File: CoreAndroid.java From a2cardboard with Apache License 2.0 | 4 votes |
/** * Executes the request and returns PluginResult. * * @param action The action to execute. * @param args JSONArry of arguments for the plugin. * @param callbackContext The callback context from which we were invoked. * @return A PluginResult object with a status and message. */ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { PluginResult.Status status = PluginResult.Status.OK; String result = ""; try { if (action.equals("clearCache")) { this.clearCache(); } else if (action.equals("show")) { // This gets called from JavaScript onCordovaReady to show the webview. // I recommend we change the name of the Message as spinner/stop is not // indicative of what this actually does (shows the webview). cordova.getActivity().runOnUiThread(new Runnable() { public void run() { webView.getPluginManager().postMessage("spinner", "stop"); } }); } else if (action.equals("loadUrl")) { this.loadUrl(args.getString(0), args.optJSONObject(1)); } else if (action.equals("cancelLoadUrl")) { //this.cancelLoadUrl(); } else if (action.equals("clearHistory")) { this.clearHistory(); } else if (action.equals("backHistory")) { this.backHistory(); } else if (action.equals("overrideButton")) { this.overrideButton(args.getString(0), args.getBoolean(1)); } else if (action.equals("overrideBackbutton")) { this.overrideBackbutton(args.getBoolean(0)); } else if (action.equals("exitApp")) { this.exitApp(); } else if (action.equals("messageChannel")) { messageChannel = callbackContext; return true; } callbackContext.sendPluginResult(new PluginResult(status, result)); return true; } catch (JSONException e) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION)); return false; } }