From 3ce770263637732d123b37ec6c56fe8a0319b96e Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 29 Sep 2020 10:18:58 +0200 Subject: [PATCH] GH-480 (android): Add option to open system's browser in a new task --- README.md | 1 + src/android/InAppBrowser.java | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5e3324926..9987cc253 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,7 @@ instance, or the system browser. - __shouldPauseOnSuspend__: Set to `yes` to make InAppBrowser WebView to pause/resume with the app to stop background audio (this may be required to avoid Google Play issues like described in [CB-11013](https://issues.apache.org/jira/browse/CB-11013)). - __useWideViewPort__: Sets whether the WebView should enable support for the "viewport" HTML meta tag or should use a wide viewport. When the value of the setting is `no`, the layout width is always set to the width of the WebView control in device-independent (CSS) pixels. When the value is `yes` and the page contains the viewport meta tag, the value of the width specified in the tag is used. If the page does not contain the tag or does not provide a width, then a wide viewport will be used. (defaults to `yes`). - __fullscreen__: Sets whether the InappBrowser WebView is displayed fullscreen or not. In fullscreen mode, the status bar is hidden. Default value is `yes`. + - __launchInNewTask__: When using target `_system`, sets to `yes` to launch system's browser in a new task. Default value is `no`. iOS supports these additional options: diff --git a/src/android/InAppBrowser.java b/src/android/InAppBrowser.java index b3e0e6126..ee566c07a 100644 --- a/src/android/InAppBrowser.java +++ b/src/android/InAppBrowser.java @@ -120,6 +120,7 @@ public class InAppBrowser extends CordovaPlugin { private static final String FOOTER_COLOR = "footercolor"; private static final String BEFORELOAD = "beforeload"; private static final String FULLSCREEN = "fullscreen"; + private static final String LAUNCH_NEW_TASK = "launchInNewTask"; private static final List customizableOptions = Arrays.asList(CLOSE_BUTTON_CAPTION, TOOLBAR_COLOR, NAVIGATION_COLOR, CLOSE_BUTTON_COLOR, FOOTER_COLOR); @@ -151,6 +152,7 @@ public class InAppBrowser extends CordovaPlugin { private String footerColor = ""; private String beforeload = ""; private boolean fullscreen = true; + private boolean launchInNewTask = false; private String[] allowedSchemes; private InAppBrowserClient currentClient; @@ -243,7 +245,7 @@ else if (url.startsWith(WebView.SCHEME_TEL)) // SYSTEM else if (SYSTEM.equals(target)) { LOG.d(LOG_TAG, "in system"); - result = openExternal(url); + result = openExternal(url, features); } // BLANK - or anything else else { @@ -461,7 +463,7 @@ private HashMap parseFeature(String optString) { * @param url the url to load. * @return "" if ok, or error message. */ - public String openExternal(String url) { + public String openExternal(String url, HashMap features) { try { Intent intent = null; intent = new Intent(Intent.ACTION_VIEW); @@ -474,6 +476,17 @@ public String openExternal(String url) { intent.setData(uri); } intent.putExtra(Browser.EXTRA_APPLICATION_ID, cordova.getActivity().getPackageName()); + + if (features != null) { + String launchNewTask = features.get(LAUNCH_NEW_TASK); + if (launchNewTask != null) { + launchInNewTask = launchNewTask.equals("yes") ? true : false; + } + } + + if (launchInNewTask) { + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + } // CB-10795: Avoid circular loops by preventing it from opening in the current app this.openExternalExcludeCurrentApp(intent); return "";