Java Code Examples for org.apache.cordova.PluginResult#setKeepCallback()

The following examples show how to use org.apache.cordova.PluginResult#setKeepCallback() . 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: ZeroConf.java    From cordova-plugin-zeroconf with MIT License 7 votes vote down vote up
public void sendCallback(String action, ServiceInfo service) {
    CallbackContext callbackContext = callbacks.get(service.getType());
    if (callbackContext == null) {
        return;
    }

    JSONObject status = new JSONObject();
    try {
        status.put("action", action);
        status.put("service", jsonifyService(service));

        Log.d(TAG, "Sending result: " + status.toString());

        PluginResult result = new PluginResult(PluginResult.Status.OK, status);
        result.setKeepCallback(true);
        callbackContext.sendPluginResult(result);

    } catch (JSONException e) {
        Log.e(TAG, e.getMessage(), e);
        callbackContext.error("Error: " + e.getMessage());
    }
}
 
Example 2
Source File: SharingReceptor.java    From cordova-sharingreceptor with MIT License 6 votes vote down vote up
private void maybePublishIntent(Intent intent) {
    if ( !SharingReceptor.isSendIntent(intent) ) {
        Log.i(TAG, "maybePublishIntent -> not publishing intent because the action name is not part of SEND_INTENTS=" + SEND_INTENTS);
    }
    else if ( this.listenerCallback == null ) {
        Log.w(TAG, "maybePublishIntent -> not publishing intent because listener callback not set");
    }
    else {

        JSONObject intentJson;
        try {
            intentJson = SharingReceptor.serializeIntent(intent);
        } catch (Exception e) {
            throw new RuntimeException("Can't serialize intent " + intent,e);
        }
        Log.i(TAG, "maybePublishIntent -> will publish intent -> " + intentJson.toString());
        PluginResult result = new PluginResult(PluginResult.Status.OK, intentJson);
        result.setKeepCallback(true);
        this.listenerCallback.sendPluginResult(result);
    }
}
 
Example 3
Source File: NetworkManager.java    From reader with MIT License 6 votes vote down vote up
/**
 * 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 4
Source File: Fingerprint.java    From cordova-plugin-fingerprint-aio with MIT License 6 votes vote down vote up
private void executeAuthenticate(JSONArray args) {
    PluginError error = canAuthenticate();
    if (error != null) {
        sendError(error);
        return;
    }
    cordova.getActivity().runOnUiThread(() -> {
        mPromptInfoBuilder.parseArgs(args);
        Intent intent = new Intent(cordova.getActivity().getApplicationContext(), BiometricActivity.class);
        intent.putExtras(mPromptInfoBuilder.build().getBundle());
        this.cordova.startActivityForResult(this, intent, REQUEST_CODE_BIOMETRIC);
    });
    PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
    pluginResult.setKeepCallback(true);
    this.mCallbackContext.sendPluginResult(pluginResult);
}
 
Example 5
Source File: FoxitPdf.java    From cordova-plugin-foxitpdf with Apache License 2.0 6 votes vote down vote up
static void onDocOpened(int errCode) {
    CallbackContext callbackContext = mCallbackArrays.get(CALLBACK_FOR_OPENDOC);
    if (callbackContext != null) {
        try {
            JSONObject obj = new JSONObject();
            obj.put("type", RDK_DOCOPENED_EVENT);
            obj.put("error", errCode);
            PluginResult.Status status;
            if (errCode == 0) {
                status = PluginResult.Status.OK;
            } else {
                status = PluginResult.Status.ERROR;
            }
            PluginResult result = new PluginResult(status, obj);
            result.setKeepCallback(true);
            callbackContext.sendPluginResult(result);
        } catch (JSONException e) {
            callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
        }
    }
}
 
Example 6
Source File: InAppBrowser.java    From phonegapbootcampsite with MIT License 5 votes vote down vote up
/**
 * Create a new plugin result and send it back to JavaScript
 *
 * @param obj a JSONObject contain event payload information
 * @param status the status code to return to the JavaScript environment
 */    
private void sendUpdate(JSONObject obj, boolean keepCallback, PluginResult.Status status) {
    if (callbackContext != null) {
        PluginResult result = new PluginResult(status, obj);
        result.setKeepCallback(keepCallback);
        callbackContext.sendPluginResult(result);
        if (!keepCallback) {
            callbackContext = null;
        }
    }
}
 
Example 7
Source File: BatteryListener.java    From jpHolo with MIT License 5 votes vote down vote up
/**
 * Create a new plugin result and send it back to JavaScript
 *
 * @param connection the network info to set as navigator.connection
 */
private void sendUpdate(JSONObject info, boolean keepCallback) {
    if (this.batteryCallbackContext != null) {
        PluginResult result = new PluginResult(PluginResult.Status.OK, info);
        result.setKeepCallback(keepCallback);
        this.batteryCallbackContext.sendPluginResult(result);
    }
}
 
Example 8
Source File: CameraPreview.java    From cordova-plugin-camera-preview with MIT License 5 votes vote down vote up
public void onStopRecordVideo(String file) {
  Log.d(TAG, "onStopRecordVideo success");

  PluginResult result = new PluginResult(PluginResult.Status.OK, file);
  result.setKeepCallback(true);

  stopRecordVideoCallbackContext.sendPluginResult(result);
}
 
Example 9
Source File: FirebaseMessagingPlugin.java    From cordova-plugin-firebase-messaging with MIT License 5 votes vote down vote up
private void sendNotification(JSONObject notificationData, CallbackContext callbackContext) {
    if (callbackContext != null) {
        PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, notificationData);
        pluginResult.setKeepCallback(true);
        callbackContext.sendPluginResult(pluginResult);
    }
}
 
Example 10
Source File: WizPurchase.java    From cordova-plugin-wizpurchase with MIT License 5 votes vote down vote up
/**
 * Retain a Callback
 *
 * @param target CallBack Instance to retain
 * @param source Source Callback instance
 **/
private void retainCallBack(CallbackContext cb) {
	// Retain callback and wait
	PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT);
	result.setKeepCallback(true);
	cb.sendPluginResult(result);
}
 
Example 11
Source File: CoreAndroid.java    From chappiecast with Mozilla Public License 2.0 5 votes vote down vote up
private void sendEventMessage(String action) {
    JSONObject obj = new JSONObject();
    try {
        obj.put("action", action);
    } catch (JSONException e) {
        LOG.e(TAG, "Failed to create event message", e);
    }
    PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, obj);
    pluginResult.setKeepCallback(true);
    if (messageChannel != null) {
        messageChannel.sendPluginResult(pluginResult);
    }
}
 
Example 12
Source File: CameraPreview.java    From cordova-plugin-camera-preview with MIT License 5 votes vote down vote up
public void onPictureTaken(String originalPicture) {
  Log.d(TAG, "returning picture");

  JSONArray data = new JSONArray();
  data.put(originalPicture);

  PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, data);
  pluginResult.setKeepCallback(fragment.tapToTakePicture);
  takePictureCallbackContext.sendPluginResult(pluginResult);
}
 
Example 13
Source File: InAppBrowser.java    From ultimate-cordova-webview-app with MIT License 5 votes vote down vote up
/**
 * Create a new plugin result and send it back to JavaScript
 *
 * @param obj a JSONObject contain event payload information
 * @param status the status code to return to the JavaScript environment
 */
private void sendUpdate(JSONObject obj, boolean keepCallback, PluginResult.Status status) {
    if (callbackContext != null) {
        PluginResult result = new PluginResult(status, obj);
        result.setKeepCallback(keepCallback);
        callbackContext.sendPluginResult(result);
        if (!keepCallback) {
            callbackContext = null;
        }
    }
}
 
Example 14
Source File: SmsReceiver.java    From Phonegap-SMS with MIT License 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {

    Bundle extras=intent.getExtras(); //get the sms map
    if(extras!=null)
    {
        Object[] smsExtra=(Object[])extras.get(SMS_EXTRA_NAME); //get received sms array

        for(int i=0;i<smsExtra.length;i++)
        {
            SmsMessage sms=SmsMessage.createFromPdu((byte[])smsExtra[i]);
            if(isReceiving && callback_receive!=null)
            {
                String formattedMsg=sms.getOriginatingAddress()+">"+sms.getMessageBody();
                PluginResult result=new PluginResult(PluginResult.Status.OK,formattedMsg);
                result.setKeepCallback(true);
                callback_receive.sendPluginResult(result);
            }
        }

        //if the plugin is active and we don't want to broadcast to other receivers
        if(isReceiving && !broadcast)
        {
            abortBroadcast();
        }
    }
}
 
Example 15
Source File: App.java    From cordova-amazon-fireos with Apache License 2.0 5 votes vote down vote up
private void sendEventMessage(String action) {
    JSONObject obj = new JSONObject();
    try {
        obj.put("action", action);
    } catch (JSONException e) {
        LOG.e(TAG, "Failed to create event message", e);
    }
    PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, obj);
    pluginResult.setKeepCallback(true);
    messageChannel.sendPluginResult(pluginResult);
}
 
Example 16
Source File: InAppServicePlugin.java    From atomic-plugins-inapps with Mozilla Public License 2.0 5 votes vote down vote up
@Override
  public void onPurchaseStart(InAppService sender, String productId)  {
if (listenerCtx != null) {
	JSONArray data = new JSONArray();
	data.put("start");
	data.put(productId);
	PluginResult result = new PluginResult(Status.OK, data);
	result.setKeepCallback(true);
	listenerCtx.sendPluginResult(result);
}
  }
 
Example 17
Source File: InAppBrowser.java    From reader with MIT License 5 votes vote down vote up
/**
 * Create a new plugin result and send it back to JavaScript
 *
 * @param obj a JSONObject contain event payload information
 * @param status the status code to return to the JavaScript environment
 */    
private void sendUpdate(JSONObject obj, boolean keepCallback, PluginResult.Status status) {
    if (callbackContext != null) {
        PluginResult result = new PluginResult(status, obj);
        result.setKeepCallback(keepCallback);
        callbackContext.sendPluginResult(result);
        if (!keepCallback) {
            callbackContext = null;
        }
    }
}
 
Example 18
Source File: NetworkManager.java    From reader with MIT License 5 votes vote down vote up
/**
 * Create a new plugin result and send it back to JavaScript
 *
 * @param connection the network info to set as navigator.connection
 */
private void sendUpdate(String type) {
    if (connectionCallbackContext != null) {
        PluginResult result = new PluginResult(PluginResult.Status.OK, type);
        result.setKeepCallback(true);
        connectionCallbackContext.sendPluginResult(result);
    }
    webView.postMessage("networkconnection", type);
}
 
Example 19
Source File: CallbackProgressDialog.java    From ultimate-cordova-webview-app with MIT License 4 votes vote down vote up
private void sendCallback() {
	PluginResult pluginResult = new PluginResult(PluginResult.Status.OK);
	pluginResult.setKeepCallback(true);
	callbackContext.sendPluginResult(pluginResult);
}
 
Example 20
Source File: VideoPlayerVLC.java    From cordova-plugin-rtsp-vlc with MIT License 4 votes vote down vote up
private void _cordovaSendResult(String event, String data) {
    PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, event);
    pluginResult.setKeepCallback(true);
    callbackContext.sendPluginResult(pluginResult);
}