From 73228af28b98b633ba0f04ddd9554ce5deea37bd Mon Sep 17 00:00:00 2001 From: Wesley Unwin Date: Tue, 30 Sep 2025 15:41:11 -0400 Subject: [PATCH] MyConnectionService: pass payload to CordovCall answer and reject, receive from and payload string from request --- src/android/MyConnectionService.java | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/src/android/MyConnectionService.java b/src/android/MyConnectionService.java index 830b8d5..0708a82 100644 --- a/src/android/MyConnectionService.java +++ b/src/android/MyConnectionService.java @@ -34,23 +34,12 @@ public static void deinitConnection() { conn = null; } - private static JSONObject convertBundleToJson(Bundle bundle) { - JSONObject jsonObject = new JSONObject(); - if (bundle != null) { - for (String key : bundle.keySet()) { - Object value = bundle.get(key); - try { - jsonObject.put(key, value); - } catch (JSONException e) { - Log.e(TAG, "Failed to convert bundle to JSON", e); - } - } - } - return jsonObject; - } - @Override public Connection onCreateIncomingConnection(final PhoneAccountHandle connectionManagerPhoneAccount, final ConnectionRequest request) { + Bundle requestExtras = request.getExtras() != null ? request.getExtras() : new Bundle(); + String fromAddress = requestExtras.getString("from"); + String payloadString = requestExtras.getString("payload"); + final Connection connection = new Connection() { @Override public void onAnswer() { @@ -82,8 +71,7 @@ public void run() { for (final CallbackContext callbackContext : callbackContexts) { CordovaCall.getCordova().getThreadPool().execute(new Runnable() { public void run() { - Bundle data = request.getExtras() != null ? request.getExtras() : new Bundle(); - PluginResult result = new PluginResult(PluginResult.Status.OK, convertBundleToJson(data)); + PluginResult result = new PluginResult(PluginResult.Status.OK, payloadString); result.setKeepCallback(true); callbackContext.sendPluginResult(result); } @@ -103,7 +91,7 @@ public void onReject() { for (final CallbackContext callbackContext : callbackContexts) { CordovaCall.getCordova().getThreadPool().execute(new Runnable() { public void run() { - PluginResult result = new PluginResult(PluginResult.Status.OK, "reject event called successfully"); + PluginResult result = new PluginResult(PluginResult.Status.OK, payloadString); result.setKeepCallback(true); callbackContext.sendPluginResult(result); } @@ -134,7 +122,8 @@ public void run() { } } }; - connection.setAddress(Uri.parse(request.getExtras().getString("from")), TelecomManager.PRESENTATION_ALLOWED); + + connection.setAddress(Uri.parse(fromAddress), TelecomManager.PRESENTATION_ALLOWED); Icon icon = CordovaCall.getIcon(); if(icon != null) { StatusHints statusHints = new StatusHints((CharSequence)"", icon, new Bundle());