List of usage examples for org.apache.cordova PluginResult PluginResult
public PluginResult(Status status, List<PluginResult> multipartMessages)
From source file:com.dude.plugins.sms.SMSPlugin.java
public void onRequestPermissionResult(int requestCode, String[] permissions, int[] grantResults) throws JSONException { for (int r : grantResults) { if (r == PackageManager.PERMISSION_DENIED) { Log.d(LOGTAG, "Permission denied"); callbackContext/*from w ww . ja va 2s. c o m*/ .sendPluginResult(new PluginResult(PluginResult.Status.ERROR, PERMISSION_DENIED_ERROR)); return; } } executeHelper(); }
From source file:com.dude.plugins.sms.SMSPlugin.java
private PluginResult sendSMS(JSONArray addressList, String text, CallbackContext callbackContext) { Log.d(LOGTAG, ACTION_SEND_SMS);/*from ww w .ja va 2 s.c o m*/ if (this.cordova.getActivity().getPackageManager().hasSystemFeature("android.hardware.telephony")) { int n; if ((n = addressList.length()) > 0) { PendingIntent sentIntent = PendingIntent.getBroadcast((Context) this.cordova.getActivity(), (int) 0, (Intent) new Intent("SENDING_SMS"), (int) 0); SmsManager sms = SmsManager.getDefault(); for (int i = 0; i < n; ++i) { String address; if ((address = addressList.optString(i)).length() <= 0) continue; sms.sendTextMessage(address, null, text, sentIntent, (PendingIntent) null); } } else { PendingIntent sentIntent = PendingIntent.getActivity((Context) this.cordova.getActivity(), (int) 0, (Intent) new Intent("android.intent.action.VIEW"), (int) 0); Intent intent = new Intent("android.intent.action.VIEW"); intent.putExtra("sms_body", text); intent.setType("vnd.android-dir/mms-sms"); try { sentIntent.send(this.cordova.getActivity().getApplicationContext(), 0, intent); } catch (PendingIntent.CanceledException e) { e.printStackTrace(); } } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, "OK")); } else { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, "SMS is not supported")); } return null; }
From source file:com.dw.bartinter.BarTinter.java
License:Open Source License
@Override public boolean execute(final String action, final CordovaArgs args, final CallbackContext callbackContext) throws JSONException { Log.v(TAG, "Executing action: " + action); final Activity activity = this.cordova.getActivity(); final Window window = activity.getWindow(); if ("_ready".equals(action)) { boolean statusBarVisible = (window.getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0; callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, statusBarVisible)); return true; }//from w w w . j a v a 2 s.c om if ("statusBar".equals(action)) { this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { try { statusBar(args.getString(0)); } catch (JSONException ignore) { Log.e(TAG, "Invalid hexString argument."); } } }); return true; } if ("navigationBar".equals(action)) { this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { try { navigationBar(args.getString(0)); } catch (JSONException ignore) { Log.e(TAG, "Invalid hexString argument."); } } }); return true; } return false; }
From source file:com.ecor.MDNS.java
License:Open Source License
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { Log.d(TAG, "Executing an action..."); this.callback = callbackContext; Log.d(TAG, "Action called: " + action); Log.d(TAG, args.toString());/*from w ww . j a va2 s. co m*/ if (action.equals("macaddress")) { Log.d(TAG, "Mac Address: " + macaddress); final CallbackContext cb = callbackContext; cordova.getThreadPool().execute(new Runnable() { public void run() { JSONObject json = new JSONObject(); try { json.put("action", new String("macaddress")); json.put("address", macaddress); PluginResult result = new PluginResult(PluginResult.Status.OK, json); result.setKeepCallback(true); cb.sendPluginResult(result); } catch (Exception e) { e.printStackTrace(); cb.error("JSON Error retrieving Mac Address."); } } }); } else if (action.equals("monitor")) { final String type = args.optString(0); if (type != null) { Log.d(TAG, "Monitor type: " + type); cordova.getThreadPool().execute(new Runnable() { public void run() { watch(type); // Thread-safe. } }); } else { callbackContext.error("Service type not specified."); return false; } } else if (action.equals("register")) { JSONObject obj = args.optJSONObject(0); if (obj != null) { final String type = obj.optString("type"); final String name = obj.optString("name"); final int port = obj.optInt("port"); final String text = obj.optString("text"); if (type == null) { callbackContext.error("Missing required service info."); return false; } cordova.getThreadPool().execute(new Runnable() { public void run() { register(type, name, port, text); } }); } else { callbackContext.error("Missing required service info."); return false; } } else if (action.equals("close")) { if (jmdns != null) { try { jmdns.close(); } catch (IOException e) { e.printStackTrace(); } } } else if (action.equals("unregister")) { if (jmdns != null) { jmdns.unregisterAllServices(); } } else { Log.e(TAG, "Invalid action: " + action); callbackContext.error("Invalid action."); return false; } PluginResult result = new PluginResult(Status.NO_RESULT); result.setKeepCallback(true); // return result; return true; }
From source file:com.ecor.MDNS.java
License:Open Source License
public void sendCallback(String action, ServiceInfo info) { JSONObject status = new JSONObject(); try {// w w w .j a v a2 s .c om status.put("action", action); status.put("service", jsonifyService(info)); Log.d(TAG, "Sending result: " + status.toString()); PluginResult result = new PluginResult(PluginResult.Status.OK, status); result.setKeepCallback(true); callback.sendPluginResult(result); } catch (JSONException e) { e.printStackTrace(); } }
From source file:com.emesonsantana.cordova.pedometer.PedometerListener.java
License:Open Source License
/** * Executes the request./*from w w w.j a v a 2 s . c o m*/ * * @param action the action to execute. * @param args the exec() arguments. * @param callbackContext the callback context used when calling back into JavaScript. * @return whether the action was valid. */ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { this.callbackContext = callbackContext; if (action.equals("isStepCountingAvailable")) { Sensor stepCounter = this.sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER); Sensor accel = this.sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); if (accel != null || stepCounter != null) { this.win(true); return true; } else { this.setStatus(PedometerListener.ERROR_NO_SENSOR_FOUND); this.win(false); return true; } } else if (action.equals("isDistanceAvailable")) { //distance is never available in Android this.win(false); return true; } else if (action.equals("isFloorCountingAvailable")) { //floor counting is never available in Android this.win(false); return true; } else if (action.equals("startPedometerUpdates")) { if (this.status != PedometerListener.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(); } PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT, ""); result.setKeepCallback(true); callbackContext.sendPluginResult(result); return true; } else if (action.equals("stopPedometerUpdates")) { if (this.status == PedometerListener.RUNNING) { this.stop(); } this.win(null); return true; } else { // Unsupported action return false; } }
From source file:com.emesonsantana.cordova.pedometer.PedometerListener.java
License:Open Source License
private void win(JSONObject message) { // Success return object PluginResult result;//from ww w. j a va2 s .co m if (message != null) result = new PluginResult(PluginResult.Status.OK, message); else result = new PluginResult(PluginResult.Status.OK); result.setKeepCallback(true); callbackContext.sendPluginResult(result); }
From source file:com.emesonsantana.cordova.pedometer.PedometerListener.java
License:Open Source License
private void win(boolean success) { // Success return object PluginResult result;/*from w w w . j ava2 s . co m*/ result = new PluginResult(PluginResult.Status.OK, success); result.setKeepCallback(true); callbackContext.sendPluginResult(result); }
From source file:com.emeth.cordova.ble.central.BLECentralPlugin.java
License:Apache License
private void listKnownDevices(CallbackContext callbackContext) { JSONArray json = new JSONArray(); // do we care about consistent order? will peripherals.values() be in order? for (Map.Entry<String, Peripheral> entry : peripherals.entrySet()) { Peripheral peripheral = entry.getValue(); json.put(peripheral.asJSONObject()); }// www . j a v a 2 s . c o m PluginResult result = new PluginResult(PluginResult.Status.OK, json); callbackContext.sendPluginResult(result); }
From source file:com.emeth.cordova.ble.central.BLECentralPlugin.java
License:Apache License
@Override public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) { String address = device.getAddress(); if (!peripherals.containsKey(address)) { Peripheral peripheral = new Peripheral(device, rssi, scanRecord); peripherals.put(device.getAddress(), peripheral); if (discoverCallback != null) { PluginResult result = new PluginResult(PluginResult.Status.OK, peripheral.asJSONObject()); result.setKeepCallback(true); discoverCallback.sendPluginResult(result); }// w w w . j av a 2 s . co m } else { // this isn't necessary Peripheral peripheral = peripherals.get(address); peripheral.updateRssi(rssi); } // TODO offer option to return duplicates }