diff --git a/src/android/ThemeableBrowser.java b/src/android/ThemeableBrowser.java index 673e0d828..063e7db28 100644 --- a/src/android/ThemeableBrowser.java +++ b/src/android/ThemeableBrowser.java @@ -33,6 +33,8 @@ Licensed to the Apache Software Foundation (ASF) under one import android.os.Build; import android.os.Bundle; import android.provider.Browser; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; import android.text.InputType; import android.text.TextUtils; import android.util.DisplayMetrics; @@ -77,6 +79,7 @@ Licensed to the Apache Software Foundation (ASF) under one import java.io.InputStream; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.List; @SuppressLint("SetJavaScriptEnabled") public class ThemeableBrowser extends CordovaPlugin { @@ -373,6 +376,7 @@ public String openExternal(String url) { this.cordova.getActivity().startActivity(intent); return ""; } catch (android.content.ActivityNotFoundException e) { + emitLog( LOAD_ERROR_EVENT, EVT_ERR, String.format("Error loading %s: %s", url, e.toString())); Log.d(LOG_TAG, "ThemeableBrowser: Error loading url "+url+":"+ e.toString()); return e.toString(); } @@ -1213,7 +1217,15 @@ public ThemeableBrowserClient(CordovaWebView webView, */ @Override public boolean shouldOverrideUrlLoading(WebView webView, String url) { - if (url.startsWith(WebView.SCHEME_TEL)) { + // handle back to application redirect without processing url by webView + final Intent customSchemeIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); + final PackageManager packageManager = cordova.getActivity().getApplicationContext().getPackageManager(); + final List resolvedActivities = packageManager.queryIntentActivities(customSchemeIntent, 0); + + String newloc = ""; + if (url.startsWith("http:") || url.startsWith("https:") || url.startsWith("file:")) { + newloc = url; + } else if (url.startsWith(WebView.SCHEME_TEL)) { try { Intent intent = new Intent(Intent.ACTION_DIAL); intent.setData(Uri.parse(url)); @@ -1262,6 +1274,18 @@ else if (url.startsWith("sms:")) { } catch (android.content.ActivityNotFoundException e) { Log.e(LOG_TAG, "Error sending sms " + url + ":" + e.toString()); } + } else if(resolvedActivities.size() > 0) { + Log.e(LOG_TAG, "Starting custom intent: " + url); + + try{ + customSchemeIntent.setFlags(Intent.URI_INTENT_SCHEME); + customSchemeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + cordova.getActivity().startActivity(customSchemeIntent); + closeDialog(); + } catch (Exception e) { + Log.e(LOG_TAG, "Custom scheme exception: " + e.toString()); + } + return true; } return false; } diff --git a/src/ios/CDVThemeableBrowser.m b/src/ios/CDVThemeableBrowser.m index ce09b20ce..2169ea7ab 100644 --- a/src/ios/CDVThemeableBrowser.m +++ b/src/ios/CDVThemeableBrowser.m @@ -1336,11 +1336,13 @@ - (float) getStatusBarOffset { - (void) rePositionViews { CGFloat toolbarHeight = [self getFloatFromDict:_browserOptions.toolbar withKey:kThemeableBrowserPropHeight withDefault:TOOLBAR_DEF_HEIGHT]; - CGFloat webviewOffset = _browserOptions.fullscreen ? 0.0 : toolbarHeight; + CGFloat statusBarOffset = [self getStatusBarOffset]; + CGFloat webviewOffset = _browserOptions.fullscreen ? 0.0 : toolbarHeight + statusBarOffset; + if ([_browserOptions.toolbarposition isEqualToString:kThemeableBrowserToolbarBarPositionTop]) { [self.webView setFrame:CGRectMake(self.webView.frame.origin.x, webviewOffset, self.webView.frame.size.width, self.webView.frame.size.height)]; - [self.toolbar setFrame:CGRectMake(self.toolbar.frame.origin.x, [self getStatusBarOffset], self.toolbar.frame.size.width, self.toolbar.frame.size.height)]; + [self.toolbar setFrame:CGRectMake(self.toolbar.frame.origin.x, statusBarOffset, self.toolbar.frame.size.width, self.toolbar.frame.size.height)]; } CGFloat screenWidth = CGRectGetWidth(self.view.frame);