From 2d1838b25032c54baf836c42aee6a9bcaafa1f93 Mon Sep 17 00:00:00 2001 From: Marta Carlos Date: Mon, 9 Dec 2024 10:49:50 +0000 Subject: [PATCH] fix(android): crash when trying to open blob urls - when trying to open blob urls, an app using the @capacitor/browser plugin would just crash, with an `ActivityNotFoundException` - the try/catch block wasn't placed properly https://outsystemsrd.atlassian.net/browse/RMET-3912 --- .../plugins/browser/BrowserPlugin.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/browser/android/src/main/java/com/capacitorjs/plugins/browser/BrowserPlugin.java b/browser/android/src/main/java/com/capacitorjs/plugins/browser/BrowserPlugin.java index 1fbc16852..5cb859402 100644 --- a/browser/android/src/main/java/com/capacitorjs/plugins/browser/BrowserPlugin.java +++ b/browser/android/src/main/java/com/capacitorjs/plugins/browser/BrowserPlugin.java @@ -60,25 +60,25 @@ public void open(PluginCall call) { } // open the browser and finish - try { - Intent intent = new Intent(getContext(), BrowserControllerActivity.class); - intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - getContext().startActivity(intent); - Integer finalToolbarColor = toolbarColor; - setBrowserControllerListener( - activity -> { + Intent intent = new Intent(getContext(), BrowserControllerActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + getContext().startActivity(intent); + + Integer finalToolbarColor = toolbarColor; + setBrowserControllerListener( + activity -> { + try { activity.open(implementation, url, finalToolbarColor); browserControllerActivityInstance = activity; call.resolve(); + } catch (ActivityNotFoundException ex) { + Logger.error(getLogTag(), ex.getLocalizedMessage(), null); + call.reject("Unable to display URL"); } - ); - } catch (ActivityNotFoundException ex) { - Logger.error(getLogTag(), ex.getLocalizedMessage(), null); - call.reject("Unable to display URL"); - return; - } + } + ); } @PluginMethod