GH-480 (android): Add option to open system's browser in a new task

This commit is contained in:
Thomas 2020-09-29 10:18:58 +02:00
parent 46c080f59a
commit 3ce7702636
2 changed files with 16 additions and 2 deletions

View File

@ -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:

View File

@ -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 @@ public class InAppBrowser extends CordovaPlugin {
// 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 @@ public class InAppBrowser extends CordovaPlugin {
* @param url the url to load.
* @return "" if ok, or error message.
*/
public String openExternal(String url) {
public String openExternal(String url, HashMap<String, String> features) {
try {
Intent intent = null;
intent = new Intent(Intent.ACTION_VIEW);
@ -474,6 +476,17 @@ public class InAppBrowser extends CordovaPlugin {
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 "";