From 114569d2463871205ea579a6d52da6df0fed1d68 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sat, 20 Feb 2021 10:04:53 +0300 Subject: [PATCH] code refactoring --- .../apache/cordova/CordovaWebViewImpl.java | 37 ++++++++----------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/framework/src/org/apache/cordova/CordovaWebViewImpl.java b/framework/src/org/apache/cordova/CordovaWebViewImpl.java index 7ff4c4c165..a1ac862458 100644 --- a/framework/src/org/apache/cordova/CordovaWebViewImpl.java +++ b/framework/src/org/apache/cordova/CordovaWebViewImpl.java @@ -229,31 +229,26 @@ public void showWebPage(String url, boolean openExternal, boolean clearHistory, return; } - Intent intent; - - if (url.startsWith("intent://")) { - try { + Intent intent = null; + try { + if (url.startsWith("intent://")) { intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME); - } catch (URISyntaxException e) { - e.printStackTrace(); - return; - } - - } else { - intent = new Intent(Intent.ACTION_VIEW); - Uri uri = Uri.parse(url); - // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent". - // Adding the MIME type to http: URLs causes them to not be handled by the downloader. - if ("file".equals(uri.getScheme())) { - intent.setDataAndType(uri, resourceApi.getMimeType(uri)); } else { - intent.setData(uri); + intent = new Intent(Intent.ACTION_VIEW); + // To send an intent without CATEGORY_BROWSER, a custom plugin should be used. + intent.addCategory(Intent.CATEGORY_BROWSABLE); + Uri uri = Uri.parse(url); + // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent". + // Adding the MIME type to http: URLs causes them to not be handled by the downloader. + if ("file".equals(uri.getScheme())) { + intent.setDataAndType(uri, resourceApi.getMimeType(uri)); + } else { + intent.setData(uri); + } } - // To send an intent without CATEGORY_BROWSER, a custom plugin should be used. - intent.addCategory(Intent.CATEGORY_BROWSABLE); - } - try { cordova.getActivity().startActivity(intent); + } catch (URISyntaxException e) { + LOG.e(TAG, "Error parsing url " + url, e); } catch (ActivityNotFoundException e) { if (url.startsWith("intent://") && intent != null && intent.getStringExtra("browser_fallback_url") != null) { showWebPage(intent.getStringExtra("browser_fallback_url"), openExternal, clearHistory, params);