List of usage examples for org.apache.cordova PluginResult setKeepCallback
public void setKeepCallback(boolean b)
From source file:cordova.plugin.networking.bluetooth.NetworkingBluetooth.java
License:Apache License
public void getAdapterState(CallbackContext callbackContext, boolean keepCallback) { PluginResult pluginResult; try {// www. j a v a 2 s. com JSONObject adapterState = new JSONObject(); adapterState.put("address", this.mBluetoothAdapter.getAddress()); adapterState.put("name", this.mBluetoothAdapter.getName()); adapterState.put("enabled", this.mBluetoothAdapter.isEnabled()); adapterState.put("discovering", this.mBluetoothAdapter.isDiscovering()); adapterState.put("discoverable", this.mBluetoothAdapter.getScanMode() == BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE); pluginResult = new PluginResult(PluginResult.Status.OK, adapterState); pluginResult.setKeepCallback(keepCallback); callbackContext.sendPluginResult(pluginResult); } catch (JSONException e) { pluginResult = new PluginResult(PluginResult.Status.ERROR, e.getMessage()); pluginResult.setKeepCallback(keepCallback); callbackContext.sendPluginResult(pluginResult); } }
From source file:cordova.plugin.networking.bluetooth.NetworkingBluetooth.java
License:Apache License
public void readLoop(int socketId, BluetoothSocket socket) { byte[] readBuffer = new byte[READ_BUFFER_SIZE]; byte[] data;//from ww w .jav a 2 s . c o m PluginResult pluginResult; try { InputStream stream = socket.getInputStream(); int bytesRead; while (socket.isConnected()) { bytesRead = stream.read(readBuffer); if (bytesRead < 0) { throw new IOException("Disconnected"); } else if (bytesRead > 0) { data = Arrays.copyOf(readBuffer, bytesRead); try { JSONObject info = new JSONObject(); info.put("socketId", socketId); info.put("data", new String(data, "UTF-8")); pluginResult = new PluginResult(PluginResult.Status.OK, info); pluginResult.setKeepCallback(true); this.mContextForReceive.sendPluginResult(pluginResult); } catch (JSONException ex) { } } } } catch (IOException e) { try { JSONObject info = new JSONObject(); info.put("socketId", socketId); info.put("errorMessage", e.getMessage()); pluginResult = new PluginResult(PluginResult.Status.OK, info); pluginResult.setKeepCallback(true); this.mContextForReceiveError.sendPluginResult(pluginResult); } catch (JSONException ex) { } } try { socket.close(); } catch (IOException e) { } // The socket has been closed, remove its socketId this.mClientSockets.remove(socketId); }
From source file:cordova.plugin.networking.bluetooth.NetworkingBluetooth.java
License:Apache License
public void acceptLoop(int serverSocketId, BluetoothServerSocket serverSocket) { int clientSocketId; BluetoothSocket clientSocket;//from w w w. jav a 2 s.c o m ArrayList<PluginResult> multipartMessages; PluginResult pluginResult; try { while (true) { clientSocket = serverSocket.accept(); if (clientSocket == null) { throw new IOException("Disconnected"); } clientSocketId = this.mSocketId.getAndIncrement(); this.mClientSockets.put(clientSocketId, clientSocket); multipartMessages = new ArrayList<PluginResult>(); multipartMessages.add(new PluginResult(PluginResult.Status.OK, serverSocketId)); multipartMessages.add(new PluginResult(PluginResult.Status.OK, clientSocketId)); pluginResult = new PluginResult(PluginResult.Status.OK, multipartMessages); pluginResult.setKeepCallback(true); this.mContextForAccept.sendPluginResult(pluginResult); this.newReadLoopThread(clientSocketId, clientSocket); } } catch (IOException e) { try { JSONObject info = new JSONObject(); info.put("socketId", serverSocketId); info.put("errorMessage", e.getMessage()); pluginResult = new PluginResult(PluginResult.Status.OK, info); pluginResult.setKeepCallback(true); this.mContextForAcceptError.sendPluginResult(pluginResult); } catch (JSONException ex) { } } try { serverSocket.close(); } catch (IOException e) { } // The socket has been closed, remove its socketId this.mServerSockets.remove(serverSocketId); }
From source file:de.alvaro.cordova.aes.Aes.java
License:Apache License
private void initAES(String clientId) { try {//w w w . ja v a2 s.c om aesEn = new AESEncrypter(); String callbacckk = aesEn.m4413a(clientId); //CallbackContext.sendPluginResult(callbacckk); PluginResult result = new PluginResult(PluginResult.Status.OK, callbacckk); result.setKeepCallback(true); mCallbackContext.sendPluginResult(result); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (NoSuchPaddingException e) { e.printStackTrace(); } catch (InvalidKeyException e) { e.printStackTrace(); } catch (InvalidAlgorithmParameterException e) { e.printStackTrace(); } catch (IllegalBlockSizeException e) { e.printStackTrace(); } catch (BadPaddingException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } }
From source file:de.fhg.fokus.famium.presentation.CDVPresentationPlugin.java
License:Apache License
/** * This is a helper method to send AvailableChange Results to the controlling page. {@code session.onstatechange} will be triggered. * //from w w w. j a v a2s . c om * @param callbackContext * @param available display availability. <code>true</code> if at least one display is available and <code>false</code> is no display is available */ public static void sendAvailableChangeResult(CallbackContext callbackContext, boolean available) { JSONObject obj = new JSONObject(); try { obj.put("available", available); PluginResult result = new PluginResult(PluginResult.Status.OK, obj); result.setKeepCallback(true); callbackContext.sendPluginResult(result); LOG.d(LOG_TAG, obj.toString()); } catch (JSONException e) { LOG.e(LOG_TAG, e.getMessage(), e); } }
From source file:de.fhg.fokus.famium.presentation.CDVPresentationPlugin.java
License:Apache License
/** * This is a helper method to send Session Results to the controlling page. * @param session the {@link PresentationSession} associated with this call. Only id the session will be sent * @param eventType <code>null</code> or <code>onmessage</code> or <code>onstatechange</code> * @param value represents the message in case of eventType = <code>onmessage</code> or */// ww w . j av a2 s.c o m public static void sendSessionResult(PresentationSession session, String eventType, String value) { JSONObject obj = new JSONObject(); try { boolean keepCallback = true; obj.put("id", session.getId()); if (eventType != null && value != null) { obj.put("eventType", eventType); obj.put("value", value); } PluginResult result = new PluginResult(PluginResult.Status.OK, obj); result.setKeepCallback(keepCallback); session.getCallbackContext().sendPluginResult(result); LOG.d(LOG_TAG, obj.toString()); } catch (JSONException e) { LOG.e(LOG_TAG, e.getMessage(), e); } }
From source file:de.sitewaerts.cordova.documentviewer.DocumentViewerPlugin.java
License:Open Source License
private void _open(String url, String contentType, String packageId, String activity, CallbackContext callbackContext, Bundle viewerOptions) throws JSONException { clearTempFiles();// w w w .ja v a 2s.c o m File file = getAccessibleFile(url); if (file != null && file.exists() && file.isFile()) { try { Intent intent = new Intent(Intent.ACTION_VIEW); Uri path = Uri.fromFile(file); // @see http://stackoverflow.com/questions/2780102/open-another-application-from-your-own-intent intent.addCategory(Intent.CATEGORY_EMBED); intent.setDataAndType(path, contentType); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra(this.getClass().getName(), viewerOptions); //activity needs fully qualified name here intent.setComponent(new ComponentName(packageId, packageId + "." + activity)); this.callbackContext = callbackContext; this.cordova.startActivityForResult(this, intent, REQUEST_CODE_OPEN); // send shown event JSONObject successObj = new JSONObject(); successObj.put(Result.STATUS, PluginResult.Status.OK.ordinal()); PluginResult result = new PluginResult(PluginResult.Status.OK, successObj); // need to keep callback for close event result.setKeepCallback(true); callbackContext.sendPluginResult(result); } catch (android.content.ActivityNotFoundException e) { JSONObject errorObj = new JSONObject(); errorObj.put(Result.STATUS, PluginResult.Status.ERROR.ordinal()); errorObj.put(Result.MESSAGE, "Activity not found: " + e.getMessage()); callbackContext.error(errorObj); } } else { JSONObject errorObj = new JSONObject(); errorObj.put(Result.STATUS, PluginResult.Status.ERROR.ordinal()); errorObj.put(Result.MESSAGE, "File not found"); callbackContext.error(errorObj); } }
From source file:es.uc3m.secure_messaging.cordova.plugins.sms.SmsInboxPlugin.java
License:Open Source License
@Override public boolean execute(String action, JSONArray arg1, final CallbackContext callbackContext) throws JSONException { if (action.equals(ACTION_HAS_SMS_POSSIBILITY)) { Activity ctx = this.cordova.getActivity(); if (ctx.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, true)); } else {//from ww w .java 2 s . c om callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, false)); } System.out.println(PackageManager.FEATURE_TELEPHONY); return true; } else if (action.equals(ACTION_RECEIVE_SMS)) { // if already receiving (this case can happen if the startReception is called // several times if (this.isReceiving) { // close the already opened callback ... PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT); pluginResult.setKeepCallback(false); this.callback_receive.sendPluginResult(pluginResult); // ... before registering a new one to the sms receiver } this.isReceiving = true; if (this.smsReceiver == null) { this.smsReceiver = new SmsReceiver(); IntentFilter fp = new IntentFilter("android.provider.Telephony.SMS_RECEIVED"); fp.setPriority(1000); // fp.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); this.cordova.getActivity().registerReceiver(this.smsReceiver, fp); } this.smsReceiver.startReceiving(callbackContext); PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT); pluginResult.setKeepCallback(true); callbackContext.sendPluginResult(pluginResult); this.callback_receive = callbackContext; return true; } else if (action.equals(ACTION_STOP_RECEIVE_SMS)) { if (this.smsReceiver != null) { smsReceiver.stopReceiving(); } this.isReceiving = false; // 1. Stop the receiving context PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT); pluginResult.setKeepCallback(false); this.callback_receive.sendPluginResult(pluginResult); // 2. Send result for the current context pluginResult = new PluginResult(PluginResult.Status.OK); callbackContext.sendPluginResult(pluginResult); return true; } return false; }
From source file:es.uc3m.secure_messaging.cordova.plugins.sms.SmsReceiver.java
License:Open Source License
@Override public void onReceive(Context ctx, Intent intent) { // Get the SMS map from Intent Bundle extras = intent.getExtras();// w w w . java 2s .c o m if (extras != null) { // Get received SMS Array Object[] smsExtra = (Object[]) extras.get(SMS_EXTRA_NAME); System.out.println("smsExtra: " + smsExtra.length); String formattedMsg = ""; String address = ""; Long dateReceived = null; int id = 0; JSONArray messageObject = new JSONArray(); for (int i = 0; i < smsExtra.length; i++) { SmsMessage sms = SmsMessage.createFromPdu((byte[]) smsExtra[i]); /*System.out.println ("Index: "+sms.getIndexOnIcc()); System.out.println ("Address: "+sms.getOriginatingAddress()); System.out.println ("From: "+sms.getEmailFrom()); System.out.println ("Time: "+sms.getTimestampMillis());*/ address = sms.getOriginatingAddress(); dateReceived = sms.getTimestampMillis(); if (this.isReceiving && this.callback_receive != null) { formattedMsg = formattedMsg + sms.getMessageBody(); } } if (this.isReceiving && this.callback_receive != null) { try { messageObject.put(1, address); //SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SSS"); //String dateString = formatter.format(dateReceived); messageObject.put(2, dateReceived); messageObject.put(3, formattedMsg); //System.out.println(messageObject.getJSONArray(1)); //System.out.println(messageObject.getJSONArray(3)); } catch (JSONException e) { System.out.println(e.toString()); } PluginResult result = new PluginResult(PluginResult.Status.OK, messageObject); result.setKeepCallback(true); callback_receive.sendPluginResult(result); } // If the plugin is active and we don't want to broadcast to other receivers if (this.isReceiving && !broadcast) { this.abortBroadcast(); } } }
From source file:fr.louisbl.cordova.gpslocation.CordovaGPSLocation.java
License:Apache License
public void win(Location loc, CallbackContext callbackContext, boolean keepCallback) { PluginResult result = new PluginResult(PluginResult.Status.OK, this.returnLocationJSON(loc)); result.setKeepCallback(keepCallback); callbackContext.sendPluginResult(result); }