List of usage examples for org.apache.cordova PluginResult PluginResult
public PluginResult(Status status, List<PluginResult> multipartMessages)
From source file:com.phonegap.plugins.opensettings.NativeSettings.java
License:BSD License
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { PluginResult.Status status = PluginResult.Status.OK; Uri packageUri = Uri.parse("package:" + this.cordova.getActivity().getPackageName()); String result = ""; //Information on settings can be found here: //http://developer.android.com/reference/android/provider/Settings.html action = args.getString(0);/*from ww w. ja va 2s .com*/ Intent intent = null; if (action.equals("accessibility")) { intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS); } else if (action.equals("account")) { intent = new Intent(android.provider.Settings.ACTION_ADD_ACCOUNT); } else if (action.equals("airplane_mode")) { intent = new Intent(android.provider.Settings.ACTION_AIRPLANE_MODE_SETTINGS); } else if (action.equals("apn")) { intent = new Intent(android.provider.Settings.ACTION_APN_SETTINGS); } else if (action.equals("application_details")) { intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS, packageUri); } else if (action.equals("application_development")) { intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS); } else if (action.equals("application")) { intent = new Intent(android.provider.Settings.ACTION_APPLICATION_SETTINGS); } //else if (action.equals("battery_saver")) { // intent = new Intent(android.provider.Settings.ACTION_BATTERY_SAVER_SETTINGS); //} else if (action.equals("bluetooth")) { intent = new Intent(android.provider.Settings.ACTION_BLUETOOTH_SETTINGS); } else if (action.equals("captioning")) { intent = new Intent(android.provider.Settings.ACTION_CAPTIONING_SETTINGS); } else if (action.equals("cast")) { intent = new Intent(android.provider.Settings.ACTION_CAST_SETTINGS); } else if (action.equals("data_roaming")) { intent = new Intent(android.provider.Settings.ACTION_DATA_ROAMING_SETTINGS); } else if (action.equals("date")) { intent = new Intent(android.provider.Settings.ACTION_DATE_SETTINGS); } else if (action.equals("about")) { intent = new Intent(android.provider.Settings.ACTION_DEVICE_INFO_SETTINGS); } else if (action.equals("display")) { intent = new Intent(android.provider.Settings.ACTION_DISPLAY_SETTINGS); } else if (action.equals("dream")) { intent = new Intent(android.provider.Settings.ACTION_DREAM_SETTINGS); } else if (action.equals("home")) { intent = new Intent(android.provider.Settings.ACTION_HOME_SETTINGS); } else if (action.equals("keyboard")) { intent = new Intent(android.provider.Settings.ACTION_INPUT_METHOD_SETTINGS); } else if (action.equals("keyboard_subtype")) { intent = new Intent(android.provider.Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS); } else if (action.equals("storage")) { intent = new Intent(android.provider.Settings.ACTION_INTERNAL_STORAGE_SETTINGS); } else if (action.equals("locale")) { intent = new Intent(android.provider.Settings.ACTION_LOCALE_SETTINGS); } else if (action.equals("location")) { intent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS); } else if (action.equals("manage_all_applications")) { intent = new Intent(android.provider.Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS); } else if (action.equals("manage_applications")) { intent = new Intent(android.provider.Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS); } else if (action.equals("memory_card")) { intent = new Intent(android.provider.Settings.ACTION_MEMORY_CARD_SETTINGS); } else if (action.equals("network")) { intent = new Intent(android.provider.Settings.ACTION_NETWORK_OPERATOR_SETTINGS); } else if (action.equals("nfcsharing")) { intent = new Intent(android.provider.Settings.ACTION_NFCSHARING_SETTINGS); } else if (action.equals("nfc_payment")) { intent = new Intent(android.provider.Settings.ACTION_NFC_PAYMENT_SETTINGS); } else if (action.equals("nfc_settings")) { intent = new Intent(android.provider.Settings.ACTION_NFC_SETTINGS); } //else if (action.equals("notification_listner")) { // intent = new Intent(android.provider.Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS); //} else if (action.equals("print")) { intent = new Intent(android.provider.Settings.ACTION_PRINT_SETTINGS); } else if (action.equals("privacy")) { intent = new Intent(android.provider.Settings.ACTION_PRIVACY_SETTINGS); } else if (action.equals("quick_launch")) { intent = new Intent(android.provider.Settings.ACTION_QUICK_LAUNCH_SETTINGS); } else if (action.equals("search")) { intent = new Intent(android.provider.Settings.ACTION_SEARCH_SETTINGS); } else if (action.equals("security")) { intent = new Intent(android.provider.Settings.ACTION_SECURITY_SETTINGS); } else if (action.equals("settings")) { intent = new Intent(android.provider.Settings.ACTION_SETTINGS); } else if (action.equals("show_regulatory_info")) { intent = new Intent(android.provider.Settings.ACTION_SHOW_REGULATORY_INFO); } else if (action.equals("sound")) { intent = new Intent(android.provider.Settings.ACTION_SOUND_SETTINGS); } else if (action.equals("store")) { intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + this.cordova.getActivity().getPackageName())); } else if (action.equals("sync")) { intent = new Intent(android.provider.Settings.ACTION_SYNC_SETTINGS); } else if (action.equals("usage")) { intent = new Intent(android.provider.Settings.ACTION_USAGE_ACCESS_SETTINGS); } else if (action.equals("user_dictionary")) { intent = new Intent(android.provider.Settings.ACTION_USER_DICTIONARY_SETTINGS); } else if (action.equals("voice_input")) { intent = new Intent(android.provider.Settings.ACTION_VOICE_INPUT_SETTINGS); } else if (action.equals("wifi_ip")) { intent = new Intent(android.provider.Settings.ACTION_WIFI_IP_SETTINGS); } else if (action.equals("wifi")) { intent = new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS); } else if (action.equals("wireless")) { intent = new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS); } else { status = PluginResult.Status.INVALID_ACTION; callbackContext.sendPluginResult(new PluginResult(status, result)); return false; } if (args.length() > 1 && args.getBoolean(1)) { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } this.cordova.getActivity().startActivity(intent); callbackContext.sendPluginResult(new PluginResult(status, result)); return true; }
From source file:com.phonegap.plugins.speech.XSpeechRecognizer.java
License:Open Source License
private void fireRecognitionEvent(ArrayList<String> transcripts, float[] confidences) { JSONObject event = new JSONObject(); JSONArray results = new JSONArray(); try {// w w w . j a v a2 s. c o m for (int i = 0; i < transcripts.size(); i++) { JSONArray alternatives = new JSONArray(); JSONObject result = new JSONObject(); result.put("transcript", transcripts.get(i)); result.put("final", true); if (confidences != null) { result.put("confidence", confidences[i]); } alternatives.put(result); results.put(alternatives); } event.put("type", "result"); // event.put("emma", null); // event.put("interpretation", null); event.put("results", results); } catch (JSONException e) { // this will never happen } PluginResult pr = new PluginResult(PluginResult.Status.OK, event); pr.setKeepCallback(true); this.callbackContext.sendPluginResult(pr); }
From source file:com.phonegap.plugins.speech.XSpeechRecognizer.java
License:Open Source License
private void fireErrorEvent(Integer code) { JSONObject event = new JSONObject(); try {/*from w ww .ja v a 2 s. c om*/ event.put("type", "error"); event.put("code", code.toString()); } catch (JSONException e) { // this will never happen } PluginResult pr = new PluginResult(PluginResult.Status.ERROR, event); pr.setKeepCallback(false); this.callbackContext.sendPluginResult(pr); }
From source file:com.phonegap.plugins.speech.XSpeechRecognizer.java
License:Open Source License
private void fireEvent(String type) { // callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, "Event")); JSONObject event = new JSONObject(); try {/* w w w . j a va 2s . c o m*/ event.put("type", type); } catch (JSONException e) { // this will never happen } // PluginResult pr = new PluginResult(PluginResult.Status.OK, "event"); PluginResult pr = new PluginResult(PluginResult.Status.OK, event); pr.setKeepCallback(true); this.callbackContext.sendPluginResult(pr); }
From source file:com.phonegap.plugins.videoplayer.VideoPlayer.java
License:BSD License
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { PluginResult.Status status = PluginResult.Status.OK; String result = ""; try {/*from w w w . j a va2 s .c om*/ if (action.equals("playVideo")) { playVideo(args.getString(0)); } else { status = PluginResult.Status.INVALID_ACTION; } callbackContext.sendPluginResult(new PluginResult(status, result)); } catch (JSONException e) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION)); } catch (IOException e) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION)); } return true; }
From source file:com.phonegap.plugins.xapkreader.XAPKReader.java
License:BSD License
@Override public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException { if (action.equals("get")) { final String filename = args.getString(0); try {/* www . j a v a 2 s. c om*/ Context ctx = cordova.getActivity().getApplicationContext(); // Read file as array buffer byte[] data = XAPKReader.readFile(ctx, filename); if (null != data) { // Encode to Base64 string String encoded = Base64.encodeToString(data, Base64.DEFAULT); // Return file data as base64 string callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, encoded)); } else { callbackContext.error("File not found."); } } catch (Exception e) { e.printStackTrace(); callbackContext.error(e.getMessage()); } return true; } return false; }
From source file:com.physicaroid.pocketduino.cordova.PocketDuino.java
License:Apache License
/** * Executes the request and returns PluginResult. * * @param action The action to execute./*from www .j a va2 s . com*/ * @param args JSONArry 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. */ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if (action.equals("setInfo")) { try { showToast(callbackContext, cordova.getActivity(), args); return true; // exec()?true???? successCallback??errorCallback?????? } catch (Exception e) { Log.e(POCKETDUINO, "Exception: " + e.getMessage()); callbackContext.error(e.getMessage()); } } else if (action.equals("setCallback")) { setCallbackTest(callbackContext); return true; // exec()?true???? successCallback??errorCallback?????? } else if (action.equals("listenDevice")) { listenUsbDevice(callbackContext); return true; // exec()?true???? successCallback??errorCallback?????? } else if (action.equals("loadHexFile")) { uploadHexFile(callbackContext, args); return true; // exec()?true???? successCallback??errorCallback?????? } else if (action.equals("startReceive")) { listenData(callbackContext); return true; // exec()?true???? successCallback??errorCallback?????? } else if (action.equals("openDevice")) { openDevice(callbackContext); return true; // exec()?true???? successCallback??errorCallback?????? } else if (action.equals("closeDevice")) { closeDevice(callbackContext); return true; // exec()?true???? successCallback??errorCallback?????? } else if (action.equals("write")) { writeSerial(callbackContext, args); return true; // exec()?true???? successCallback??errorCallback?????? } else { PluginResult dataResult = new PluginResult(PluginResult.Status.INVALID_ACTION, "Invalid Action"); callbackContext.sendPluginResult(dataResult); } return false; }
From source file:com.physicaroid.pocketduino.cordova.PocketDuino.java
License:Apache License
private void setCallbackTest(CallbackContext callbackContext) { try {// w w w .j a v a2s.c o m String json = "{\"message\": \"conntected\"}"; JSONObject parameter = new JSONObject(json); PluginResult dataResult = new PluginResult(PluginResult.Status.OK, parameter); dataResult.setKeepCallback(true); callbackContext.sendPluginResult(dataResult); } catch (JSONException e) { Log.e(POCKETDUINO, "Exception: " + e.getMessage()); callbackContext.error(e.toString()); } }
From source file:com.physicaroid.pocketduino.cordova.PocketDuino.java
License:Apache License
/** * USB???//from w w w . j a va 2 s . co m */ private void listenUsbDevice(CallbackContext callbackContext) { IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED); intentFilter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED); this.usbCallbackContext = callbackContext; if (this.mUsbReceiver == null) { this.mUsbReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String handlerName = null; String action = intent.getAction(); if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) { // plugin result of USB attached handlerName = HANDLER_PREFIX + "." + "attached"; } if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) { // plugin result of USB detached handlerName = HANDLER_PREFIX + "." + "detached"; } try { String json = "{\"handlerName\":" + handlerName + " }"; JSONObject parameter = new JSONObject(json); PluginResult dataResult = new PluginResult(PluginResult.Status.OK, parameter); dataResult.setKeepCallback(true); usbCallbackContext.sendPluginResult(dataResult); } catch (JSONException e) { Log.e(POCKETDUINO, "Exception: " + e.getMessage()); usbCallbackContext.error(e.toString()); } } }; webView.getContext().registerReceiver(this.mUsbReceiver, intentFilter); } }
From source file:com.physicaroid.pocketduino.cordova.PocketDuino.java
License:Apache License
private void listenData(CallbackContext callbackContext) { this.dataCallbackContext = callbackContext; if (mPhysicaloid.isOpened()) { mPhysicaloid.addReadListener(new ReadLisener() { // callback when reading one or more size buffer @Override/* w ww . j a v a 2 s. c o m*/ public void onRead(int size) { byte[] buf = new byte[size]; int readSize = mPhysicaloid.read(buf, size); //Log.d(POCKETDUINO, String.format("%02d ", size)); if (readSize > 2) { try { String hexString = bytesToHex(buf); String handlerName = "pocketduino.receive"; String json = "{\"handlerName\":" + handlerName + ", \"data\":" + hexString + " }"; //String json = "{\"handlerName\":" + handlerName + " }"; JSONObject parameter = new JSONObject(json); PluginResult dataResult = new PluginResult(PluginResult.Status.OK, parameter); dataResult.setKeepCallback(true); dataCallbackContext.sendPluginResult(dataResult); } catch (JSONException e) { Log.e(POCKETDUINO, "Exception: " + e.getMessage()); dataCallbackContext.error(e.toString()); } } } }); } else { PluginResult dataResult = new PluginResult(PluginResult.Status.ERROR); dataResult.setKeepCallback(true); this.dataCallbackContext.sendPluginResult(dataResult); this.dataCallbackContext = null; } }